I'm trying to recreate this sample app that is supplied with flask-bootstrap, but have run into an issue rendering the navbar. I get the error: inja2.exceptions.UndefinedError: 'flask_nav.Nav object' has no attribute 'fronend_top'
The example app is here: https://github.com/mbr/flask-bootstrap/tree/master/sample_app
And the flask-nav example is here: http://pythonhosted.org/flask-nav/getting-started.html#rendering-the-navbar
As far as I can tell I'm doing what seems to be correct, but I guess the nav isn't being passed to the web page context? Not sure.
Here is my 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)
And here is the line that is throwing the error in my base.html
{% block navbar %}
{{nav.fronend_top.render()}}
{% endblock %}
Thanks for any help!
Are you trying this with
flask-boostrap4
? If so, i found that it's Navbar Renderer is broken and causes the same error you found. Usingflask-boostrap
v3 along with BS 3 seems to fix it.