Numeric for loop in Django templates

Lev picture Lev · Jul 10, 2009 · Viewed 243.3k times · Source

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

for i = 1 to n

Answer

Udi picture Udi · Apr 22, 2011

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