-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
flask中的上下文处理器app_context_processor
app_context_processor在flask中被称作上下文处理器,借助app_context_processor我们可以让所有自定义变量在模板中可见,如下面的代码,我们将email作为一个变量在所有模板中可见:
@main.app_context_processor
def admin_email():
email='879651072@qq.com'
return dict(email='879651072@qq.com') 1、app_context_processor作为一个装饰器修饰一个函数。
2、函数的返回结果必须是dict,届时dict中的key将作为变量在所有模板中可见。
管理员邮箱:<a href="mailto:{{email}}">{{email}}</a>
# 管理员邮箱: 879651072@qq.comReactions are currently unavailable