我在一页中显示20行内容,我能够显示S.No 1到20,我使用分页器转到下一页,当我在每一页中选择下一页时,返回上一页,它只显示1到20。它在转到下一页时不会显示,在转到上一页时也不会减少。如何按增量顺序显示S.No
{% for child in children.object_list %}
<tr><td width="15%">strong>Sl.no</strong>{{forloop.counter}}</td>
</tr>
{% endfor %}
<div class="pagination">
<span class="step-links">
{% if children.has_next %}
<a href="?page={{ children.next_page_number }}"> Previous </a>
{% endif %}
<span class="current">
Page {{ children.number }} of {{ children.paginator.num_pages }}.
</span>
{% if children.has_previous %}
<a href="?page={{ children.previous_page_number }}"> Next </a>
{% endif %}
<br>
</span>
</div>发布于 2012-09-17 18:01:53
在您的模板中写入以下内容以显示项目编号
{% for child in children.object_list %}
<tr><td width="15%">strong>Sl.no</strong>
{{ forloop.counter0|add:children.start_index}} </td>
</tr>
{% endfor %}{{forloop.counter}}将始终从0开始。
发布于 2012-09-17 17:43:43
我总是使用django-pagination来做这类事情。它使用几个模板标签为您完成所有困难的工作……
https://stackoverflow.com/questions/12456522
复制相似问题