How to increment a variable on a for loop in jinja template?

前端 未结 7 2097
旧时难觅i
旧时难觅i 2020-11-27 12:02

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}}
         


        
7条回答
  •  一向
    一向 (楼主)
    2020-11-27 12:26

    if anyone want to add a value inside loop then you can use this its working 100%

    {% set ftotal= {'total': 0} %} 
    {%- for pe in payment_entry -%}
        {% if ftotal.update({'total': ftotal.total + 5}) %}{% endif %} 
    {%- endfor -%}
    
    {{ftotal.total}}
    

    output = 5

提交回复
热议问题