Django代码

class Test(APIView):

    # pindex为页码,
    def get(self, request):
        print(request.query_params)
        pindex = request.query_params["page_id"]
        # 1、获取数据
        goods_list = People.objects.all()
        # 2、创建分页
        paginat = Paginator(goods_list, 2)
        # 3、获取分页页码
        page_list = [i for i in paginat.page_range]
        #    获取当前页的数据
        paged = paginat.page(pindex)
        # 4、 序列化
        goods_serializer = PeopleSerializer(paged, many=True)
        # 5、返回数据
        return Response({
            "page_list": page_list,
            "data": goods_serializer.data
        })

results matching ""

    No results matching ""