flask-bootstrap
flask-bootstrap copied to clipboard
i got “unresolved templates reference ‘bootstrap/base.html’ ” problem on the “base.html”
i am learning the flask-bootstrap ,and i am already import this module,and i can run the code,but i did not see the bootstrap style for the ’index1.html‘ i hope somebody can help me,thanks。
1.the code《sample.py》: `from flask import Flask, render_template, request, redirect, url_for, make_response, abort from werkzeug.routing import BaseConverter from werkzeug.utils import secure_filename from flask_script import Manager from os import path from flask_bootstrap import Bootstrap
class RegexConverter(BaseConverter): def init(self, url_map, *items): super(RegexConverter, self).init(url_map) self.regex = items[0]
app = Flask(name) app.url_map.converters['regex'] = RegexConverter
bootstrap = Bootstrap(app) manager = Manager(app)
@app.route('/') def index1(): # abort(400) response = make_response(render_template('index1.html', title='Welcome')) response.set_cookie('username', 'te') return response
@app.route('/services') def services(): return 'services'
@app.route('/about') def about(): return 'about'
@app.route('/user/<regex("[a-z]{3}"):user_id>') def user(user_id): return 'user %s' % user_id
@app.route('/projects/') @app.route('/ourworks/') def projects(): return 'the project page'
@app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] # else: # username = request.args['username'] return render_template('login.html', methods=request.method)
@app.route('/upload', methods=['GET', 'POST']) def upload(): if request.method == 'POST': f = request.files['file']
# filename = secure_filename(f.filename)
# f.save(path.join('static/uploads', filename))
# basepath = path.abspath(path.dirname(__file__))
# upload_path = path.join(basepath, 'static/uploads')
# f.save(upload_path,secure_filename(f.filename))
basepath = path.abspath(path.dirname(__file__))
filename = secure_filename(f.filename)
upload_path = path.join(basepath, 'static', 'uploads', filename)
f.save(upload_path)
return redirect(url_for('upload'))
return render_template('upload.html')
@app.errorhandler(404) def page_not_found(error): return render_template('404.html'), 404
@app.template_test('current_link') def is_current_link(link): return link == request.path
@manager.command def dev(): from livereload import Server live_server = Server(app.wsgi_app) live_server.watch('**/.') live_server.serve(open_url=True)
if name == 'main': # app.run(debug=True) manager.run() `
2.the code《base.html》 `{% extends 'bootstrap/base.html' %}
{% block head %} {{ super() }} {% include 'includes/_html.html' %} {% endblock %}
{% block content %}
{% block footer %} {% endblock %} `
3.the code《index1.html》: `{% extends 'base.html' %}
{% import'_macro.html' as ui %}
{% block title %}{{ title }}{% endblock %}
{% block content %} {% set links=[ ('主页',url_for('.index1')), ('关于',url_for('.about')), ('服务',url_for('.services')), ('项目',url_for('.projects')), ] %}
{% for label,href in links %}
{% if not loop.first %} | {% endif %}
<a href="{% if href is current_link %}
{% else %}
{{ href }}
{% endif %}">
{{ label }}</a>
{% endfor %}
</nav>
<h1>{{ self.title() }}</h1>
{{ ui.input('username') }}
{{ ui.input('password',type='password' ) }}
{% endblock content %}
`
me too
me too too