Jinja2包含中访问变量

2024-04-27 03:19:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的基本模板中包括一个模板,我渲染的模板扩展了这个模板。我在direct模板中设置了一个变量,并尝试在包含的模板中使用它。我希望下面的输出Active,但是没有输出。为什么header.html看不到变量active?在

主.py

@app.route("/")
def root():
    return render_template("page.html")

页面.html

^{pr2}$

基本.html

{% include "header.html" %}

页眉.html

{% if active %}Active{% endif %}

Tags: py模板appreturndefhtmlpagetemplate