The problem might be that the generic views list method (like ListApiView) 
returns a list of objects it the page is None.

    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)

The problem might be in the default pagination class (in 
PageNumberPagination the page_size_query_param is set to None). To fix this 
I have created a custom pagination class:
https://gist.github.com/robintema/a2dee269041325d19d47d78853ed4572

Use it by overwriting the default pagination class:
REST_FRAMEWORK = {
…
    'DEFAULT_PAGINATION_CLASS': 
‘path.to.pagination.CustomPageNumberPagination',
…
}



On Wednesday, November 2, 2016 at 3:13:37 PM UTC+2, David Miranda wrote:
>
> Yes! Any suspicion of what might be ?
>
> Regards
>
> quarta-feira, 2 de Novembro de 2016 às 10:57:18 UTC, Norbert Mate escreveu:
>>
>> Hi,
>>   does this happen if the result size is smaller than the requested items 
>> per page? Example: you have 3 items in the db and from the frontend you 
>> request 10.
>>
>> Regards,
>> Norbert.
>>
>> On Monday, October 31, 2016 at 9:43:27 PM UTC+2, David Miranda wrote:
>>>
>>> Hi,
>>>
>>> The pagination in my APIs (ModelViewSet) does not always work. Sometimes 
>>> returns the paged results and sometimes not (the get_paginated_response 
>>> method is not executed). I have the settings set pagination class and the 
>>> PAGE_SIZE parameter. A
>>> Thanks
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to