Xavier,
Thanks for the reply. The paginator object was not getting passed to the
templates. The problem was in my list function, it was creating a new
paginator manually and not through the GenericAPIView methods. So there are
a couple ways to fix it:
1. Manually assign the paginator to the GenericAPIView
def list(self, request):
#Get the queryset (not a django queryset)
queryset = self.get_queryset()
#Run it through the paginator
paginator = self.pagination_class()
objects = paginator.paginate_queryset(queryset, request)
#Serialize the list of objects
serializer = self.serializer_class(objects, many=True)
self._paginator = paginator
return paginator.get_paginated_response(serializer.data)
2. Use the GenericAPIView to get the paginator and response
def list(self, request):
#Get the queryset (not a django queryset)
queryset = self.get_queryset()
#Run it through the paginator
objects = self.paginate_queryset(query)
#Serialize the list of objects
serializer = self.get_serializer(objects, many=True)
return self.get_paginated_response(serializer.data)
Either way the GenericAPIView passes the pagination object to the templates
and it work.
Thanks again,
Angus
On Wednesday, 15 March 2017 13:21:31 UTC-6, Xavier Ordoquy wrote:
>
> Hi Angus,
>
> The first thing would be to fire django debug toolbar and investigate
> whether the pagination is passed to the context.
> If it isn’t there’s something in your code that prevents it.
> If it is, you’ll have to go through the templates to figure.
>
> Regards,
> Xavier Ordoquy,
> Linovia.
--
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.