{% if type == "Cryptography" %}
{% include 'Cryptography/_____.html' %}
{% elif type == "Password Cracking" %}
{% include 'PasswordCracking/_____.html' %}
{% endif %}
在模板中,我想在C和PC目录中包含一些带有1.html 2.html 3.html的HTML页面。我曾尝试过这样的操作,其中页面是我的参数变量。
{% if type == "Cryptography" %}
{% include 'cryptography/'{{page}}'html' %}
{% elif type == "Password Cracking" %}
{% include 'PasswordCracking/'{{page}}'.html' %}
{% endif %}
查看此
def lessons(request, foo, page):
return render(request, 'lessons.html', {'type': foo, 'page': page})
注意:类型和页面是我的论点
答案 0 :(得分:1)
您可以使用add
过滤器来连接字符串
{% if type == "Cryptography" %}
{% include "cryptography/"|add:page|add:".html" %}
{% elif type == "Password Cracking" %}
{% include "PasswordCracking/"|add:page|add:".html" %}
{% endif %}