Django-在模板列表中获取元素索引

Wes*_*Gun 1 python django django-templates

我在模板中有一个列表用于迭代,并且在进行迭代时,我想在此列表中打印其索引。现在,我正在使用list.index(element),但这是行不通的。

我做:

<tbody>
   {% for core in cores %}
   <tr>
       <td>{{cores.index(core)}}</td>     <!-- this line doesn't work -->
       <td>{{core.user}}</td>             <!-- this line works. -->
Run Code Online (Sandbox Code Playgroud)

这样不是吗?我该怎么办for i in length(cores)

Taj*_*ngh 5

{{forloop.counter}}就是这个。仅在元素之前添加此行