How to use Pagination in a Non-Generic View/Viewset?

Viewed 3621

Prologue:

I have seen this question arising in more than one posts:

and can also be applied here:

I have composed an example on SO Documentation to unify my answers in the above questions but since the Documentation will get shutdown on August 8 2017, I will follow the suggestion of this widely upvoted and discussed meta answer and transform my example to a self-answered post.

Of course I would be more than happy to see any different approach as well!!


Question:

I want to use a Non Generic View/Viewset (eg: APIView) on a Django Rest Framework project.
As I read on the pagination documentation:

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.

Can I still continue using a non generic view/viewset?
How can I implement pagination on it?

1 Answers
Related