后端设置
def get_all_goods(request):
goods = Goods.objects.all()
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
p = Paginator(goods, 10)
goods = p.page(page)
return render(request, 'goods_list.html', {'data': goods})
前端设置
<div id="pages" class="text-left">
<nav>
<ul class="pagination">
<li class="step-links">
{% if data.has_previous %}
<a class='active' href="?kw=all&page={{ data.previous_page_number }}">上一页</a>
{% endif %}
<span class="current">
Page {{ data.number }} of {{ data.paginator.num_pages }} </span>
{% if data.has_next %}
<a class='active' href="?kw=all&page={{ data.next_page_number }}">下一页</a>
{% endif %}
</li>
</ul>
</nav>
</div>
效果图
屏幕快照 2019-04-21 下午11.25.41.png