Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 能否将变量插入模板中的{%include%}语句中?_Django_Django Templates - Fatal编程技术网

Django 能否将变量插入模板中的{%include%}语句中?

Django 能否将变量插入模板中的{%include%}语句中?,django,django-templates,Django,Django Templates,我知道可以在include语句中直接使用变量: {%include template name%} 但是我有一个变量,它只包含文件名的一部分。所以我想说一些像 {%include{{name}.hmtl%} 如何实现此效果?您可以使用: {% with name|add:".html" as template %} {% include template %} {% endwith %}

我知道可以在include语句中直接使用变量:

{%include template name%}

但是我有一个变量,它只包含文件名的一部分。所以我想说一些像

{%include{{name}.hmtl%}

如何实现此效果?

您可以使用:

{% with name|add:".html" as template %}
    {% include template %}
{% endwith %}