【发布时间】:2019-01-03 22:12:42
【问题描述】:
我从这个链接学习了 Django 的分页基础知识: https://simpleisbetterthancomplex.com/tutorial/2016/08/03/how-to-paginate-with-django.html
但是!我唯一的问题是我想在不更改 url 的情况下进行分页。
也就是说,我的意思是当 html 页面中有多个表格时,我需要对表格进行分页。
如何只对一张表进行分页???
我的代码:
这是html模板的基本结构:
...
<table class="uk-table uk-table-striped">
<tbody>
{% for post_status in post.statusPage %}
<tr>
<td>{{ post_status.status_time }}</td>
<td>{{ post_status.repost_count }}</td>
<td>{{ post_status.comment_count }}</td>
<td>{{ post_status.like_count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if post.statusPage.has_other_pages %}
<ul class="uk-pagination uk-flex-center" uk-margin>
{% if post.statusPage.has_previous %}
<li><a href="#"><span uk-pagination-previous></span></a></li>
{% else %}
<li><a><span uk-pagination-previous></span></a></li>
{% endif %}
{% for i in post.statusPage.paginator.page_range %}
{% if post.statusPage.number == i %}
<li class="uk-active"><span>{{ i }}</span></li>
{% else %}
<li><a href="#">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if post.statusPage.has_next %}
<li><a href="#"><span uk-pagination-next></span></a></li>
{% else %}
<li><a><span uk-pagination-next></span></a></li>
{% endif %}
</ul>
{% endif %}
在模板中,有多个帖子对象
post
每个帖子都有自己的表格和分页器:
post.statusPage
是帖子的页面对象。
【问题讨论】:
标签: python html django html-table pagination