In this code Flask Nav works until I add the Flask Bootstrap code:
from flask import Flask, render_template
from flask_bootstrap import Bootstrap
from flask_nav import Nav
from flask_nav.elements import Navbar, Subgroup, View, Link, Text, Separator
app = Flask(__name__)
nav = Nav(app)
nav.register_element('my_navbar', Navbar(
'thenav',
View('Home Page', 'index'),
View('Item', 'item', item=1),
Separator(),
Link('Google', 'https://www.google.com'),
Separator(),
Text('Some text'),
Subgroup('Extras',
Link('Yahoo', 'https://www.yahoo.com'),
View('Index', 'index')
)
))
Bootstrap(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/items/<item>')
def item(item):
return '<h2>The item is {} </h2>'.format(item)
if __name__ == '__main__':
app.run(debug=True)
As soon as Flask Bootstrap is added I get
AttributeError: 'Navbar' object has no attribute 'kwargs'
I had this problem too when using flask-boostrap 4.0.2 because I was aiming to use Bootstrap 4. Reverting to flask-bootstrap 3.3.7.1, it started working (provided I also used Boostrap 3.3.7). At the time of writing, 3.3.7.1 seems to be the latest version of flask-boostrap and is 2 years stale. The alleged "flask-bootstrap4" is going on a year of no new releases, and doesn't seem to have a public git repo for folks to contribute to. I believe the
nav.Bootstraprenderer
class is broken in v4, yet v3 code doesn't render NavBars properly if using BS4.After spending a couple hours on this, i'm not so sure we get a lot using flask-boostrap: it's not hard to just maintain our own Jinja2 base template importing the versions of BS we want, along with the basic blocks.