7π
β
Take a look how it is done in drf itself:
class ListModelMixin(object):
"""
List a queryset.
"""
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
Hope that this will help you β as is self-explanatory;
You used GenericAPIView
β and overwrite the get β you should use the get_paginated_response
method to achieve pagination.
Happy coding.
π€opalczynski
0π
In my case, I was passing wrong argument in query param for page no.
It was page
but I was passing page_no
π€user14475872
- [Django]-Django Query, filter by user group
- [Django]-Django: paginating differently on the first page
- [Django]-Django URLs β trailing slash gets added to variable value
Source:stackexchange.com