django中的连续数字标签模板

consecutive numbers tag template in django

我的排名只有return前3,这是queryset

queryset = Ranking.objects.filter(puzzle_id=self.kwargs['pk']).order_by('segundos')[:3]

在我的模板中有一个 table:

<tbody>
       {% for ranking in object_list %}
        <tr>
          <th scope="row"></th>
          <td>{{ranking.usuario}}</td>
          <td>{{ranking.segundos}}</td>          
        </tr>
        {% endfor %}

在第一个 <th> 标签中,我需要一个模板标签 return 第一行 1,第二行 2,第三行 3,我知道解决方案可以很简单,但我试过没有成功。

使用 {% for %} 循环中可用的 forloop.counter 变量:

{% for ranking in object_list %}
  <tr>
    <th scope="row">{{ forloop.counter }}</th>
    <td>{{ranking.usuario}}</td>
    <td>{{ranking.segundos}}</td>          
  </tr>
{% endfor %}