I have try to paginate my data.. but this is not work , I'm still getting all data from DataBase this is views.py :
class User_apiView(APIView):
pagination_class=PageNumberPagination
def get(self, request):
user = User.objects.all()
# pagination_class=PageNumberPagination
serializer = TripSerializer(user, many = True)
return Response(serializer.data)
this is settings.py :
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 2,
}
this the data I recieve in this url http://127.0.0.1:8000/api/users/?PAGE=4&PAGE_SIZE=1
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
[
{
"id": 115,
"is_normaluser": null,
"is_agency": null,
"last_login": "2022-02-11T20:28:13.506519Z",
"is_superuser": true,
"first_name": "qaz",
},
{
"id": 115,
"is_normaluser": null,
"is_agency": null,
"last_login": "2022-02-11T20:28:13.506519Z",
"is_superuser": true,
"first_name": "qaz",
},
{
"id": 115,
"is_normaluser": null,
"is_agency": null,
"last_login": "2022-02-11T20:28:13.506519Z",
"is_superuser": true,
"first_name": "qaz",
},
]
getmethod, you omit the pagination part...Pagination is only performed automatically if you're using the generic views or viewsets. If you're using a regular APIView, you'll need to call into the pagination API yourself to ensure you return a paginated response. See the source code for the mixins.ListModelMixin and generics.GenericAPIView classes for an example