繁体   English   中英

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

[英]Pass variable to included template in 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'

我究竟做错了什么?

您必须先声明变量,然后再包含子模板

{% block footer %}
    {% with var="foo" %}
        {% include  "_footer.html" %}
    {% endwith %}
{% endblock %}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM