将变量传递给 django 中包含的模板

我正在尝试将变量传递给子模板:


{% block footer %}

    {% include '_footer.html'  with var="foo" %}

{% endblock footer %}

但我收到 django 错误:


Exception Type: TemplateSyntaxError at /

Exception Value: expected token 'end of statement block', got 'with'

我究竟做错了什么?


大话西游666
浏览 119回答 1
1回答

隔江千里

您必须先声明变量,然后包含子模板{% block footer %}    {% with var="foo" %}        {% include  "_footer.html" %}    {% endwith %}{% endblock %}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python