mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
fix 404 when page query parameter is empty string (#8578)
* fix 404 when page query parameter is empty string * Update pagination.py * Update pagination.py Co-authored-by: Tom Christie <tom@tomchristie.com>
This commit is contained in:
parent
03c2ef1787
commit
0ae3323bd2
|
@ -218,7 +218,7 @@ class PageNumberPagination(BasePagination):
|
||||||
return list(self.page)
|
return list(self.page)
|
||||||
|
|
||||||
def get_page_number(self, request, paginator):
|
def get_page_number(self, request, paginator):
|
||||||
page_number = request.query_params.get(self.page_query_param, 1)
|
page_number = request.query_params.get(self.page_query_param) or 1
|
||||||
if page_number in self.last_page_strings:
|
if page_number in self.last_page_strings:
|
||||||
page_number = paginator.num_pages
|
page_number = paginator.num_pages
|
||||||
return page_number
|
return page_number
|
||||||
|
|
|
@ -180,8 +180,9 @@ class TestPageNumberPagination:
|
||||||
def get_html_context(self):
|
def get_html_context(self):
|
||||||
return self.pagination.get_html_context()
|
return self.pagination.get_html_context()
|
||||||
|
|
||||||
def test_no_page_number(self):
|
@pytest.mark.parametrize('url', ['/', '/?page='])
|
||||||
request = Request(factory.get('/'))
|
def test_no_page_number(self, url):
|
||||||
|
request = Request(factory.get(url))
|
||||||
queryset = self.paginate_queryset(request)
|
queryset = self.paginate_queryset(request)
|
||||||
content = self.get_paginated_content(queryset)
|
content = self.get_paginated_content(queryset)
|
||||||
context = self.get_html_context()
|
context = self.get_html_context()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user