Numeric for loop in Django templates

后端 未结 19 861
温柔的废话
温柔的废话 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:05

    I tried very hard on this question, and I find the best answer here: (from how to loop 7 times in the django templates)

    You can even access the idx!

    views.py:

    context['loop_times'] = range(1, 8)
    

    html:

    {% for i in loop_times %}
            
    {% endfor %}
    

提交回复
热议问题