Django的自动增量值 [英] auto increment value in django
本文介绍了Django的自动增量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在django中有一张桌子,并尝试自动递增其序列号.自定义模板中的for循环用于变量.
i have an table in django and try to auto increment it's serial no. in custom template for loop is used for the variables.
自定义模板
{% for i in getodeskview %}
<tr>
<td> 1. </td>
<td>{{ i.odesk_id }}</td>
<td>{{ i.hours }}</td>
<td>{{ i.feedback }}</td>
<td>
<a href="/odesk/?editodeskform={{i.id}} " title="Edit"><i class="splashy-document_letter_edit"></i></a>
<!---- <a href="/hours/?addhid={{i.app_id}}" title="Interview"><i class="splashy-document_letter_okay"></i></a>----->
<a href="/deleteodesk/?dltodid={{i.id}}" title="Remove"><i class="splashy-document_letter_remove"></i></a>
</td>
</tr>
{% endfor %}
如何增加值.
推荐答案
在循环内使用 {{forloop.counter}}
来获取索引.
Use {{ forloop.counter }}
inside loop to get the index.
https://docs.djangoproject.com/zh/1.5/ref/templates/builtins/#for
这篇关于Django的自动增量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文