Python 如何在{%include%}标记django中包含我的参数?
在一个模板中,我想包含一些包含1.HTML2.HTML3.HTML的HTML页面,它们位于C和PC目录中。我试过这样做,页面是我的参数变量Python 如何在{%include%}标记django中包含我的参数?,python,django,django-templates,django-views,Python,Django,Django Templates,Django Views,在一个模板中,我想包含一些包含1.HTML2.HTML3.HTML的HTML页面,它们位于C和PC目录中。我试过这样做,页面是我的参数变量 {% if type == "Cryptography" %} {% include 'Cryptography/_____.html' %} {% elif type == "Password Cracking" %} {% include 'PasswordCracking/_____.html' %}
{% if type == "Cryptography" %}
{% include 'Cryptography/_____.html' %}
{% elif type == "Password Cracking" %}
{% include 'PasswordCracking/_____.html' %}
{% endif %}
对此的看法
{% if type == "Cryptography" %}
{% include 'cryptography/'{{page}}'html' %}
{% elif type == "Password Cracking" %}
{% include 'PasswordCracking/'{{page}}'.html' %}
{% endif %}
注意:type和page是我的参数您可以使用筛选器连接字符串
def lessons(request, foo, page):
return render(request, 'lessons.html', {'type': foo, 'page': page})
谢谢,老兄,你帮我节省了时间。但是你忘记了“.in”.html”
{% if type == "Cryptography" %}
{% include "cryptography/"|add:page|add:".html" %}
{% elif type == "Password Cracking" %}
{% include "PasswordCracking/"|add:page|add:".html" %}
{% endif %}