Building a list in Django templates

后端 未结 7 1018
慢半拍i
慢半拍i 2020-12-05 13:14

With this code:

{% for o in [1,2,3] %}
    
{% cycle \'row1\' \'row2\' %}
{% endf
7条回答
  •  猫巷女王i
    2020-12-05 13:41

    You can do it via cunning use of the make_list filter, but it's probably a bad idea:

    {% for o in "123"|make_list %}
        
    {% cycle 'row1' 'row2' %}
    {% endfor %}

    p.s. You don't seem to be using o anywhere, so I'm not sure what you're trying to do.

提交回复
热议问题