首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在{% include } tag django中包含我的参数?

如何在{% include } tag django中包含我的参数?
EN

Stack Overflow用户
提问于 2019-12-30 06:21:01
回答 1查看 77关注 0票数 0
代码语言:javascript
复制
    {% if type == "Cryptography" %}
        {% include 'Cryptography/_____.html' %}
    {% elif type == "Password Cracking" %}
        {% include 'PasswordCracking/_____.html' %}
    {% endif %}

在模板中,我希望包含一些包含1.html 2.html 3.html的HTML页面,这些页面位于C和PC目录中。我尝试过这样做,其中页面是我的参数变量。

代码语言:javascript
复制
    {% if type == "Cryptography" %}
        {% include 'cryptography/'{{page}}'html' %}
    {% elif type == "Password Cracking" %}
        {% include 'PasswordCracking/'{{page}}'.html' %}
    {% endif %}

视图中的

代码语言:javascript
复制
def lessons(request, foo, page):
    return render(request, 'lessons.html', {'type': foo, 'page': page})

注释:类型和页面是我的参数

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-30 06:33:17

可以使用add筛选器连接字符串。

代码语言:javascript
复制
{% if type == "Cryptography" %}
    {% include "cryptography/"|add:page|add:".html" %}
{% elif type == "Password Cracking" %}
    {% include "PasswordCracking/"|add:page|add:".html" %}
{% endif %}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59526540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档