Building a list in Django templates

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

With this code:

{% for o in [1,2,3] %}
    
{% cycle \'row1\' \'row2\' %}
{% endf
7条回答
  •  悲哀的现实
    2020-12-05 13:42

    We can use split method on str object :

    page.html :

    {% with '1 2 3' as list %}
      {% for i in list.split %}
        {{ i }}
    {% endfor %} {% endwith %}

    Results :

    1
    2
    3
    

提交回复
热议问题