The DRF docs state that:
Pagination is only performed automatically if you're using the generic views or viewsets.
But I'm using a ModelViewSet
which inherits from ViewSet
, so I tell myself "Cool, all I have to do is add this to my settings.py
":
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 12, # for 12-col grid css frameworks
However, this didn't work.
If I send a GET request for 27 items it returns all of them (in both the browsable API and json).
- Am I right in thinking I should only be returned 12?
- Sub-question: PAGE_SIZE is the number of top-level objects returned per page, right? I saw a few examples with
PAGINATE_BY
but it doesn't feature in the source so I presume it's deprecated?
I'm using DRF 3.6.3, django 1.11.2.
Edit: my settings:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 12,
}
I've also added pagination_class = PageNumberPagination
to the ModelViewSet
class, without effect.
Here's the verification from the shell that the Pagination class does know the page size it's supposed to provide:
>>> from rest_framework.pagination import PageNumberPagination
>>> p = PageNumberPagination()
>>> p.max_page_size
>>> print(p.page_size)
12