Building a list in Django templates

后端 未结 7 1005
慢半拍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.

    0 讨论(0)
提交回复
热议问题