How to output loop.counter in python jinja template?

后端 未结 5 527
-上瘾入骨i
-上瘾入骨i 2020-12-02 06:59

I want to be able to output the current loop iteration to my template.

According to the docs: http://wsgiarea.pocoo.org/jinja/docs/loops.html, there is a loop.count

5条回答
  •  借酒劲吻你
    2020-12-02 07:04

    if you are using django use forloop.counter instead of loop.counter

      {% for user in userlist %}
    • {{ user }} {{forloop.counter}}
    • {% if forloop.counter == 1 %} This is the First user {% endif %} {% endfor %}

提交回复
热议问题