You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api-guide/pagination.md
+5-23Lines changed: 5 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -242,29 +242,6 @@ We'd then need to setup the custom class in our configuration:
242
242
243
243
Note that if you care about how the ordering of keys is displayed in responses in the browsable API you might choose to use an `OrderedDict` when constructing the body of paginated responses, but this is optional.
244
244
245
-
## Header based pagination
246
-
247
-
Let's modify the built-in `PageNumberPagination` style, so that instead of include the pagination links in the body of the response, we'll instead include a `Link` header, in a [similar style to the GitHub API][github-link-pagination].
248
-
249
-
class LinkHeaderPagination(pagination.PageNumberPagination):
250
-
def get_paginated_response(self, data):
251
-
next_url = self.get_next_link()
252
-
previous_url = self.get_previous_link()
253
-
254
-
if next_url is not None and previous_url is not None:
255
-
link = '<{next_url}>; rel="next", <{previous_url}>; rel="prev"'
256
-
elif next_url is not None:
257
-
link = '<{next_url}>; rel="next"'
258
-
elif previous_url is not None:
259
-
link = '<{previous_url}>; rel="prev"'
260
-
else:
261
-
link = ''
262
-
263
-
link = link.format(next_url=next_url, previous_url=previous_url)
264
-
headers = {'Link': link} if link else {}
265
-
266
-
return Response(data, headers=headers)
267
-
268
245
## Using your custom pagination class
269
246
270
247
To have your custom pagination class be used by default, use the `DEFAULT_PAGINATION_CLASS` setting:
@@ -328,10 +305,15 @@ The [`DRF-extensions` package][drf-extensions] includes a [`PaginateByMaxMixin`
328
305
329
306
The [`drf-proxy-pagination` package][drf-proxy-pagination] includes a `ProxyPagination` class which allows to choose pagination class with a query parameter.
330
307
308
+
## link-header-pagination
309
+
310
+
The [`django-rest-framework-link-header-pagination` package][drf-link-header-pagination] includes a `LinkHeaderPagination` class which provides pagination via an HTTP `Link` header as desribed in [Github's developer documentation](github-link-pagination).
0 commit comments