分页展示
分页导包
from django.core.paginator import Paginator
#查询数据库中的这个表的所有数据
onecate = Onecate.objects.all()
# 每页显示几条
page_count = 1
# 当前第几页
try:
p = int(request.POST.get('p'))
except:
p = 1
#利用了paginator内置函数的特性
page = Paginator(onecate,page_count)
onecatelist = page.get_page(p)
totalpage = page.num_pages
HTML代码
引入jquery包
<link rel="stylesheet" href="../../static/admin/css/jquery.pagination.css">
<script src="../../static/admin/js/jquery-1.12.4.min.js"></script>
<script src="../../static/admin/js/jquery.pagination.min.js"></script>
注意顺序
设置一个div
<div id='pagination'>
</div>
-------------------------
<script>
$(function(){
$('#pagination').pagination({
currentPage:{{p}},
totalPage:{{totalpage}},
callback:function(current){
window.location.href='/goods/my_index?p='+current
}
})
})
</script>
{{forloop.counter}}-----序号自增
<img src='{{i.image_url}}'>----图片显示
- get形式分页
views.py
def get(self, request):
# 目标数据量
law = models.T_lawyer.objects.all()
# 实例化分页器 每页显示10条
paginator = Paginator(law, 10)
# 获取传来的页码数
p = request.GET.get('p',1)
# 每页的数据量
lawyer = paginator.page(p)
# 总共多少页
totalpage = paginator.num_pages
return render(request, 'admin/lawyer_review.html', locals())
html