aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide
diff options
context:
space:
mode:
authorTom Christie2015-01-14 17:46:41 +0000
committerTom Christie2015-01-14 17:46:41 +0000
commit313aa727e3c44016e531a7af75051fc6e6d7cb96 (patch)
tree95dd1fa7eed81fc716daafdf7477b1671879c621 /docs/api-guide
parent3833a5bb8a9174e5fb09dac59a964eff24b6065e (diff)
downloaddjango-rest-framework-313aa727e3c44016e531a7af75051fc6e6d7cb96.tar.bz2
Tweaks
Diffstat (limited to 'docs/api-guide')
-rw-r--r--docs/api-guide/pagination.md19
1 files changed, 15 insertions, 4 deletions
diff --git a/docs/api-guide/pagination.md b/docs/api-guide/pagination.md
index 9fbeb22a..ba71a303 100644
--- a/docs/api-guide/pagination.md
+++ b/docs/api-guide/pagination.md
@@ -74,7 +74,7 @@ Note that the `paginate_queryset` method may set state on the pagination instanc
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].
- class LinkHeaderPagination(PageNumberPagination)
+ class LinkHeaderPagination(pagination.PageNumberPagination):
def get_paginated_response(self, data):
next_url = self.get_next_link() previous_url = self.get_previous_link()
@@ -82,7 +82,7 @@ Let's modify the built-in `PageNumberPagination` style, so that instead of inclu
link = '<{next_url}; rel="next">, <{previous_url}; rel="prev">'
elif next_url is not None:
link = '<{next_url}; rel="next">'
- elif prev_url is not None:
+ elif previous_url is not None:
link = '<{previous_url}; rel="prev">'
else:
link = ''
@@ -97,10 +97,20 @@ Let's modify the built-in `PageNumberPagination` style, so that instead of inclu
To have your custom pagination class be used by default, use the `DEFAULT_PAGINATION_CLASS` setting:
REST_FRAMEWORK = {
- 'DEFAULT_PAGINATION_CLASS':
- 'my_project.apps.core.pagination.LinkHeaderPagination',
+ 'DEFAULT_PAGINATION_CLASS': 'my_project.apps.core.pagination.LinkHeaderPagination',
+ 'PAGINATE_BY': 10
}
+API responses for list endpoints will now include a `Link` header, instead of including the pagination links as part of the body of the response, for example:
+
+---
+
+![Link Header][link-header]
+
+*A custom pagination style, using the 'Link' header'*
+
+---
+
# Third party packages
The following third party packages are also available.
@@ -111,5 +121,6 @@ The [`DRF-extensions` package][drf-extensions] includes a [`PaginateByMaxMixin`
[cite]: https://docs.djangoproject.com/en/dev/topics/pagination/
[github-link-pagination]: https://developer.github.com/guides/traversing-with-pagination/
+[link-header]: ../img/link-header-pagination.png
[drf-extensions]: http://chibisov.github.io/drf-extensions/docs/
[paginate-by-max-mixin]: http://chibisov.github.io/drf-extensions/docs/#paginatebymaxmixin