Python 更新Flask中上下文处理器传递的全局变量时失败

Python 更新Flask中上下文处理器传递的全局变量时失败,python,flask,Python,Flask,如何更新上下文处理器传递的flask中的全局变量? 我在index.html中尝试了以下方法,它对index.html有效,但对其他html文件无效 //(1) inside index.html {% set user = [3,4] %} {{user}} //(2) 内部init.py val = [1,2] @app.context_processor def inject_user(): return dict(user=val) //(3) insidelayou

如何更新上下文处理器传递的flask中的全局变量? 我在index.html中尝试了以下方法,它对index.html有效,但对其他html文件无效

//(1) inside index.html

{% set user = [3,4] %}
{{user}} 
//(2) 内部init.py

val = [1,2]

@app.context_processor

def inject_user():

    return dict(user=val)
//(3) insidelayout.html

{{ user }}
因此,我刷新网页,我希望看到layout.html将打印[3,4],但它仍然打印[1,2]。 你知道怎么做吗?
谢谢。

index.html是您的基本模板吗?谢谢您的回复。layout.html是基础。index.html扩展了它。index.html扩展了layout.html。layout.html是index.html的父级。所以,在索引中设置的内容不会在布局中设置。如果在布局中设置[3.4],则只有布局将打印[3,4]。