Opened 7 years ago
Closed 7 years ago
#28843 closed Uncategorized (invalid)
Pagination: previous_page_number shouldn't raise exception when page=1
Reported by: | Scot Hacker | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 2.0 |
Severity: | Normal | Keywords: | pagination |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
According to Django 2.0 docs:
https://docs.djangoproject.com/en/2.0/topics/pagination/
It should be possible to use:
<a href="?page={{ contacts.previous_page_number }}">previous</a>
But if you're looking at /contacts/?page=1 , or /contacts, then previous_page_number() resolves to 0, which throws an exception. It's not even possible to use
{% if contacts.previous_page_number %}
as it raises the same error. It seems that this method causes a site crash when on page 1, no matter what.
Propose: previous_page_number should return 0 if it can't go any further back rather than raise an exception.
Related to:
https://code.djangoproject.com/ticket/17159
Change History (3)
comment:1 by , 7 years ago
Summary: | previous_page_number shouldn't raise exception when page=1 → Pagination: previous_page_number shouldn't raise exception when page=1 |
---|
comment:2 by , 7 years ago
comment:3 by , 7 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Apologies. I realize now that I wasn't wrapping the call in
if page.has_previous
. Stupid mistake, sorry,