梅州建站方法,昆明市住房和城乡建设局门户网站,软件界面设计方案,购买网站建设需要注意app.errorhandler(404) # 传入要处理的错误代码
def page_not_found(e): # 接受异常对象作为参数user User.query.first()return render_template(404.html, useruser), 404 # 返回模板和状态码对于多个模板内都需要使用的变量#xff0c;我们可以使用 app.context_proces…app.errorhandler(404) # 传入要处理的错误代码
def page_not_found(e): # 接受异常对象作为参数user User.query.first()return render_template(404.html, useruser), 404 # 返回模板和状态码对于多个模板内都需要使用的变量我们可以使用 app.context_processor 装饰器注册一个模板上下文处理函数。这个函数返回的变量以字典键值对的形式将会统一注入到每一个模板的上下文环境中因此可以直接在模板中使用。
app.context_processor
def inject_user(): # 函数名可以随意修改user User.query.first()return dict(useruser) # 需要返回字典等同于 return {user: user}app.context_processor
def inject_user():user User.query.first()return dict(useruser)app.errorhandler(404)
def page_not_found(e):return render_template(404.html), 404app.route(/)
def index():movies Movie.query.all()return render_template(index.html, moviesmovies)模板继承
{% block content %} {% endblock %}{% extends base.html %}{% block content %} {% endblock %}