简体   繁体   中英

Pass variable to included template in django

I am trying to pass variable to child template:

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

but I am getting django error:

Exception Type: TemplateSyntaxError at /
Exception Value: expected token 'end of statement block', got 'with'

What am I doing wrong?

you must declare variable first then include child template

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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