Building a list in Django templates

后端 未结 7 1009
慢半拍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:43

    drodger is correct, you can't do that in the deliberately-crippled Django template lanuage. Either pass in the list as a context variable when you invoke the template or try a template tag like expr. Then you can say {% expr [1,2,3] as my_list %} and then use my_list in your for loop.

提交回复
热议问题