I am using APIView
for get and post items.
I wanted to implement pagination for my API using Django Rest Framework, but it is not working.
I want
You could make your life a lot easier and just use a ListView. By overriding render_to_response you can make it output json instead of HTML. It does all the pagination for you.
from django.core import serializers
from django.views.generic import ListView
class MyListView(JSONResponseMixin, ListView):
model = models.BaseItem
paginate_by = 10
def render_to_response(self, context):
return JsonResponse(
serializers.serialize("json", context),
**response_kwargs
)