问题
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