在此代码中,Flask Nav 一直有效,直到我添加 Flask Bootstrap 代码:
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)
添加 Flask Bootstrap 后,我得到
AttributeError:“导航栏”对象没有属性“kwargs”