Django: how to set pagination in resfulapi?

痴心易碎 提交于 2020-04-18 01:09:11

问题


here i tried django default pagination in my views, query works perfectly but pagination does not work for me. what should i do? i guess i have to make a custom pagination as per my code. it would be great if anybody could help me where i made mistake in my code.

from rest_framework.pagination import PageNumberPagination
class DefaultResultsSetPagination(PageNumberPagination):
    page_size = 2
    page_size_query_param = 'page_size'
    max_page_size = 100000

class Order_ListAPIView(APIView):
    pagination_class = DefaultResultsSetPagination
    def get(self,request,format=None):

        if request.method == 'GET':
            cur,conn = connection()
            order_query = ''' SELECT * FROM orders'''
            order_detail_query = ''' SELECT * FROM order_details'''


            ...
             ... #rest_code
              ...


            return Response({"order_data":order_data},status=status.HTTP_200_OK)
        else:
            return Response(status=status.HTTP_400_BAD_REQUEST)

settings:

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 2
}

来源:https://stackoverflow.com/questions/60540700/django-how-to-set-pagination-in-resfulapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!