如何在django模板中创建计数器循环? [英] how to create counter loop in django template?

查看:77
本文介绍了如何在django模板中创建计数器循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以告诉我如何在django中写下c代码

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 error

{% for(c=0; c<5; c++)%}
     <div class="tab-content">
    <h1 class="tab" title="title for page 1">Page 1</h1>
    <p>This is the content of tab 1 on container 1</p>
     </div>     
{% endfor %}


推荐答案

当你渲染你的模板,你可以通过范围

When you render your template, you may pass range

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

在html模板中,可能就是这样

And in html template, probably like this

{% for i in range5 %}
    <div class="tab-content">
    <h1 class="tab" title="title for page {{i}}">Page {{i}}</h1>
    <p>This is the content of tab {{i}} on container {{i}}</p>
    </div>  
{% endfor %}

这篇关于如何在django模板中创建计数器循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆