在Jinja2的include中访问变量

4

我在我的基本模板中包含一个模板,该模板被我渲染的模板所扩展。我在直接模板中设置了一个变量,并尝试在包含的模板中使用它。我希望以下内容输出Active,但实际上没有任何输出。为什么header.html无法看到变量active

main.py

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

page.html

{% set active = True %}
{% extends "base.html" %}

base.html

{% include "header.html" %}

header.html

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

4
这是一个未解决的问题:https://github.com/mitsuhiko/jinja2/issues/352 - r-m-n
1个回答

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接