我正在尝试重新创建flask-bootstrap 提供的这个示例应用程序,但在呈现导航栏时遇到了问题。我收到错误:inja2.exceptions.UndefinedError: 'flask_nav.Nav object' has no attribute 'fronend_top'
示例应用程序在这里: https ://github.com/mbr/flask-bootstrap/tree/master/sample_app
烧瓶导航示例在这里: http: //pythonhosted.org/flask-nav/getting-started.html#rendering-the-navbar
据我所知,我正在做的事情似乎是正确的,但我猜导航没有被传递给网页上下文?没有把握。
这是我的 server.py
from flask import Blueprint, render_template, flash, redirect, url_for
from flask_bootstrap import __version__ as FLASK_BOOTSTRAP_VERSION
from flask_bootstrap import Bootstrap
from flask_nav.elements import Navbar, View, Subgroup, Link, Text, Separator
from markupsafe import escape
from flask_nav import Nav
from forms import SignupForm
from flask import Flask
#from nav import nav
frontend = Blueprint('frontend', __name__)
# We're adding a navbar as well through flask-navbar. In our example, the
# navbar has an usual amount of Link-Elements, more commonly you will have a
# lot more View instances.
nav = Nav()
nav.register_element('frontend_top', Navbar(
View('Flask-Bootstrap', '.index'),
View('Home', '.index'),
View('Forms Example', '.example_form'),
View('Debug-Info', 'debug.debug_root'), ))
# Our index-page just shows a quick explanation. Check out the template
# "templates/index.html" documentation for more details.
@frontend.route('/')
def index():
return render_template('index.html', nav=nav)
app = Flask(__name__)
app.register_blueprint(frontend)
bootstrap = Bootstrap(app)
nav.init_app(app)
app.run(debug=True)
这是在我的 base.html 中引发错误的行
{% block navbar %}
{{nav.fronend_top.render()}}
{% endblock %}
谢谢你的帮助!