# settings.py
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 3
}
이렇게 설정하고 나면
{
"count": 1023
"next": "https://api.example.org/accounts/?page=5",
"previous": "https://api.example.org/accounts/?page=3",
"results": [
…
]
}
# pagination.py
from rest_framework.pagination import PageNumberPagination
class SmallSetPagination(PageNumberPagination):
page_size = 3
# views.py
class EbookListCreateAPIView(generics.ListCreateAPIView):
queryset = Ebook.objects.all().order_by("id")
serializer_class = EbookSerializer
permission_classes = [IsAdminUserOrReadOnly]
pagination_class = SmallSetPagination