Numeric for loop in Django templates

后端 未结 19 1216
温柔的废话
温柔的废话 2020-11-22 03:29

How do I write a numeric for loop in a Django template? I mean something like

for i = 1 to n
19条回答
  •  梦谈多话
    2020-11-22 04:00

    I've used a simple technique that works nicely for small cases with no special tags and no additional context. Sometimes this comes in handy

    {% for i in '0123456789'|make_list %}
        {{ forloop.counter }}
    {% endfor %}
    

提交回复
热议问题