To inject new variables automatically into the context of a template,
context processors exist in Flask. Context processors run before the
template is rendered and have the ability to inject new values into
the template context. A context processor is a function that returns a
dictionary. The keys and values of this dictionary are then merged
with the template context, for all templates in the app:
编写您自己的呈现方法不要重复该代码。然后在需要呈现模板时调用它。
您可以使用Flask's Context Processors将全局变量注入您的jinja模板
下面是一个例子:
相关问题 更多 >
编程相关推荐