How to output loop.counter in python jinja template?

后端 未结 5 524
-上瘾入骨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:00

    in python:

    env = Environment(loader=FileSystemLoader("templates"))
    env.globals["enumerate"] = enumerate
    

    in template:

    {% for k,v in enumerate(list) %}
    {% endfor %}
    

提交回复
热议问题