increment a variable in django templates

后端 未结 3 1712
不知归路
不知归路 2021-02-05 22:45

All,

How Can we increment a value like the following in django templates,

  {{ flag =0 }}

  {% for op in options %}
   {{op.choices}}

        
3条回答
  •  后悔当初
    2021-02-05 23:22

    You explicitly can't do that in a template. Variable assignment is not allowed.

    However if all you want is a counter in your loop, you just need to use {{ forloop.counter }}.

提交回复
热议问题