diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 50e5aaacb..f5c5b913b 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -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 diff --git a/tests/test_pagination.py b/tests/test_pagination.py index 74a65bf50..2812c4489 100644 --- a/tests/test_pagination.py +++ b/tests/test_pagination.py @@ -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()