how to create counter loop in django template?

后端 未结 3 1579
無奈伤痛
無奈伤痛 2021-01-29 12:28

can any tell me how can I write below code of c in django

for(c=0; c<5; c++)
  //do something

i had tried below code but it gives me an erro

3条回答
  •  执笔经年
    2021-01-29 13:00

    When you render your template, you may pass range

    render_to_response('template_x.html', {'range5': range(5)})
    

    And in html template, probably like this

    {% for i in range5 %}
        

    Page {{i}}

    This is the content of tab {{i}} on container {{i}}

    {% endfor %}

提交回复
热议问题