首先要实现分页查询必须给定俩个参数page(当前页数)和pages(每页显示的数据量,即显示几条数据):
代码:
from django.core.paginator import Paginator
def select_master(request):
page=int(request.POST.get('page'))
pageSize=int(request.POST.get('pageSize'))
res={}
master_list=Master.objects.all() #查询整个Master
#创建分页对象
ptr=Paginator(master_list,pageSize)
res['total']=ptr.count
masters=ptr.page(page)
res['list']=masters
res['list'] = json.loads(serializers.serialize("json",masters))
return JsonResponse(res)
---------------------
作者:廉少
来源:简书
版权声明:本文为博主原创文章,转载请附上博文链接!