BasePagination
Base class for all pagination classes.Methods
paginate_queryset(queryset, request, view=None)
Paginate a queryset if required, either returning a page object, or None if pagination is not configured.
The queryset to paginate
The request instance
The view instance (optional)
get_paginated_response(data)
Return a Response object containing paginated data.
The serialized data for the page
get_paginated_response_schema(schema)
Return the schema for paginated responses.
The schema for the results
PageNumberPagination
A simple page number based pagination style that accepts a single number page number in the request query parameters.Attributes
Number of items per page. Defaults to
None (pagination disabled)The Django Paginator class to use. Default is
django.core.paginator.PaginatorQuery parameter name for the page number. Default is
'page'Query parameter name for page size. Default is
None (client cannot control page size)Maximum allowable page size. Only relevant if
page_size_query_param is setValues that can be used to request the final page. Default is
('last',)Template name for rendering pagination controls. Default is
'rest_framework/pagination/numbers.html'Response Format
Methods
get_page_number(request, paginator)
Get the page number from the request query parameters.
get_next_link()
Return the URL for the next page, or None if there is no next page.
get_previous_link()
Return the URL for the previous page, or None if there is no previous page.
LimitOffsetPagination
A limit/offset based pagination style that mirrors the syntax used when looking up multiple database records.Attributes
Default number of items to return. Defaults to
None (pagination disabled)Query parameter name for the limit. Default is
'limit'Query parameter name for the offset. Default is
'offset'Maximum allowable limit value. Default is
NoneTemplate name for rendering pagination controls. Default is
'rest_framework/pagination/numbers.html'Response Format
Methods
get_limit(request)
Get the limit from the request query parameters.
get_offset(request)
Get the offset from the request query parameters.
get_count(queryset)
Determine the object count, supporting either querysets or regular lists.
CursorPagination
Cursor-based pagination ensures consistent results even when items are being inserted or deleted. It works by using an opaque cursor value that the client uses to navigate through the results.Attributes
Number of items per page. Defaults to
None (pagination disabled)Query parameter name for the cursor. Default is
'cursor'Field(s) to use for ordering. Default is
'-created'. Must be an unchanging, unique or nearly-unique fieldQuery parameter name for page size. Default is
NoneMaximum allowable page size. Only relevant if
page_size_query_param is setMaximum offset value to guard against malicious queries. Default is
1000Template name for rendering pagination controls. Default is
'rest_framework/pagination/previous_and_next.html'Response Format
Methods
get_ordering(request, queryset, view)
Return a tuple of strings that may be used in an order_by method.
decode_cursor(request)
Given a request with a cursor, return a Cursor instance.
encode_cursor(cursor)
Given a Cursor instance, return a URL with encoded cursor.
