Getting started¶
To create a navigational element with Flask-Nav, it must first be created and
registered on the application. Usually, your navigation should be a
Navbar
instance:
from flask_nav.elements import Navbar, View
topbar = Navbar('',
View('Home', 'frontend.index'),
View('Your Account', 'frontend.account_info'),
)
Items are added by simply passing them to the Navbar
-constructor.
This is purely convenience, instead it is possible to append to the items
attribute of topbar
as well. Each View
instance gets a piece of
text to display as the first parameter, everything afterwards is passed on
straight to url_for()
.
Registering the bar¶
It is possible to just pass in a navigational element as a normal parameter to
render_template()
. Usually it does make sense to register it
on our extension instance using register_element()
:
from flask_nav import Nav
nav = Nav()
nav.register_element('top', topbar)
# [...]
# later on, initialize your app:
nav.init_app(app)