I would like to do something like:
variable p is from test.py which is a list ['a','b','c','d']
{% for i in p %} {{variable++}} {{variable}}
result output is:
1 2 3 4
You could use loop.index
:
{% for i in p %} {{ loop.index }} {% endfor %}
Check the template designer documentation.
In more recent versions, due to scoping rules, the following would not work:
{% set count = 1 %} {% for i in p %} {{ count }} {% set count = count + 1 %} {% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With