from flask import render_template as real_render_template
from yourapp import user # Import the user variable or set it
def render_template(*args, **kwargs):
return real_render_template(*args, **kwargs, user=user)
也可以通过functools.partial完成:
from flask import render_template as real_render_template
from yourapp import user # Import the user variable or set it
from functools import partial
render_template = partial(real_render_template, user=user)
如果要向所有路由/页面/模板发送变量。您可以在flask中使用会话
现在,您可以在代码中的任何地方使用它,使用session['x']
在模板中
可以通过使用以下实现创建自定义渲染模板函数来执行此操作
也可以通过
functools.partial
完成:相关问题 更多 >
编程相关推荐