小编Eth*_*han的帖子

如何将forloop.counter连接到我的django模板中的字符串

我已经尝试连接这样的:

{% for choice in choice_dict %}
    {% if choice =='2' %}
        {% with "mod"|add:forloop.counter|add:".html" as template %}
            {% include template %}
        {% endwith %}                   
    {% endif %}
{% endfor %}    
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,我只得到"mod.html"而不是forloop.counter号码.有谁知道发生了什么以及我可以做些什么来解决这个问题?非常感谢!

python django for-loop string-concatenation django-templates

19
推荐指数
1
解决办法
1万
查看次数