[Django]-Django Rest Framework global pagination and pagination_class are not working

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

Leave a comment