使用此代码:
{% for o in [1,2,3] %}
<div class="{% cycle 'row1' 'row2' %}">
{% cycle 'row1' 'row2' %}
</div>
{% endfor %}
我得了TemplateSyntaxError
分:
Could not parse the remainder: '[1,2,3]' from '[1,2,3]'
有没有在模板中构建列表的方法?
使用此代码:
{% for o in [1,2,3] %}
<div class="{% cycle 'row1' 'row2' %}">
{% cycle 'row1' 'row2' %}
</div>
{% endfor %}
我得了TemplateSyntaxError
分:
Could not parse the remainder: '[1,2,3]' from '[1,2,3]'
有没有在模板中构建列表的方法?
你可以通过巧妙地使用make_list
个过滤来做到这一点,但这可能不是一个好主意:
{% for o in "123"|make_list %}
<div class="{% cycle 'row1' 'row2' %}">
{% cycle 'row1' 'row2' %}
</div>
{% endfor %}
P.S.您似乎没有在任何地方使用o
,所以我不确定您要做什么.