Django REST framework(DRF) APIView Implement Pagination

Prabin Karki

--

Django provides a few classes that help you manage paginated data — that is, data that’s split across several pages, with “Previous/Next” links. As apiview is a Django own customize API, pagination can be done by different method.Step to be implemented for APIVIew Pagination are as follows.

Setp 1. Import REST framework Pagination

Django REST Framework provide three way of importing a pagination they are:

PageNumberPagination

LimitOffsetPagination

CursorPagination

In this case, we use LimitOffsetPagination now create a pagination.py file and set up a pagination class:

Setp 2. Setup pagination_class

The LimitOffsetPagination class includes a number of attributes that may be overridden to modify the pagination style.To set these attributes you should override the LimitOffsetPagination class, and then enable your custom pagination class.Here in LimitOffsetPagination class

default_limt : A numeric value indicating the limit to use if one is not provided by the client in a query parameter.

max_limit : It is a numeric value indicating the maximum allowable limit that may be requested by the client.

Setp 3. Setup APIView

before setup a apiview import a BasicPagination and PaginationHandlerMixin from pagination

Now APIView Pagination is ready to use.

Thank for watching.

If you still have any issues with this implementation let me know in the comments.

--

--

Responses (1)