How to paginate with filters in django rest framework

Not sure how helpful that would be, but I needed to paginate a single view in my project that uses filter. what i did was

class GlobalFilter(CustomMixin):

    from rest_framework.pagination import PageNumberPagination

    queryset = Data.objects.all()
    filter_backends = [DjangoFilterBackend]
    serializer_class = FilterSerializer
    filterset_class = GlobalFilterSet
    pagination_class = PageNumberPagination
    pagination_class.page_size = 100

Could be helpful for someone else maybe :)


Check out the docs for those settings:

PAGINATE_BY_PARAM

The name of a query parameter, which can be used by the client to overide the default page size to use for pagination. If set to None, clients may not override the default page size.

Simply remove that line from your settings.py and you should be fine.

UPDATE 1/7/2016:

Note that this setting is now in the process of deprecation. You can consult the pagination guide for more details.

The short version is that you should now create a custom Pagination class with the appropriate settings which you then apply to your view. The examples in linked guide should be more than helpful.