我在我的基本模板中包括一个模板,我渲染的模板扩展了这个模板。我在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 %}
它似乎是一个bug,如https://github.com/mitsuhiko/jinja2/issues/352所述。在
解决方法包括在include之前访问变量。在
基本.html
相关问题 更多 >
编程相关推荐