Skip to content

Allow 'get_page' method for overriding #7626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion rest_framework/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def paginate_queryset(self, queryset, request, view=None):
return None

paginator = self.django_paginator_class(queryset, page_size)
page_number = request.query_params.get(self.page_query_param, 1)
page_number = self.get_page_number(request)
if page_number in self.last_page_strings:
page_number = paginator.num_pages

Expand Down Expand Up @@ -264,6 +264,14 @@ def get_page_size(self, request):

return self.page_size

def get_page_number(self, request):
# This can be negative to mean 'pages from the end'. Invalid values
# are ignored, and the default is page 1.
try:
return int(request.query_params.get(self.page_query_param, 1))
except ValueError:
return 1

def get_next_link(self):
if not self.page.has_next():
return None
Expand Down