我希望能够基于对象的内容生成导航栏,基本上具有一个导航栏数组或类来保存子页面,并生成具有折叠部分的适当导航栏等。我在PHP中具有Laravel的经验,类似于烧瓶,但我想不出一种简单的方法。我将不得不为每个页面提供一组数据对象,因为它是布局的一部分,但希望不必为每个页面专门指定它。有办法吗?
到目前为止,我只有基础知识,应用程序工厂,视图和蓝图:
工厂
def create_app():
app = flask(__name__)
app.config.from_pyfile('config.py')
app.register_blueprint(blueprint_index)
return app
蓝图
from flask import Blueprint,render_template,session
blueprint_index = Blueprint('simple_page',__name__)
@blueprint_index.route('/')
def index():
if 'text' in session:
session['text'] += 1
else:
session['text'] = 0
return render_template('pages/index.html',text=str(session['text']))
忽略我添加到路由中的少量调试文本。