mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-21 17:16:47 +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)
|
||||
|
||||
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:
|
||||
page_number = paginator.num_pages
|
||||
return page_number
|
||||
|
|
|
@ -180,8 +180,9 @@ class TestPageNumberPagination:
|
|||
def get_html_context(self):
|
||||
return self.pagination.get_html_context()
|
||||
|
||||
def test_no_page_number(self):
|
||||
request = Request(factory.get('/'))
|
||||
@pytest.mark.parametrize('url', ['/', '/?page='])
|
||||
def test_no_page_number(self, url):
|
||||
request = Request(factory.get(url))
|
||||
queryset = self.paginate_queryset(request)
|
||||
content = self.get_paginated_content(queryset)
|
||||
context = self.get_html_context()
|
||||
|
|
Loading…
Reference in New Issue
Block a user