Opened 9 years ago
Closed 9 years ago
#28036 closed Uncategorized (invalid)
Unexpected exception raised by previous_page_number() method - Django Paginator
| Reported by: | Pat | Owned by: | Pat |
|---|---|---|---|
| Component: | Uncategorized | Version: | 1.10 |
| Severity: | Normal | Keywords: | paginator, InvalidPage |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
>>> objects = ['john', 'paul', 'george', 'ringo']
>>> p = Paginator(objects, 2)
>>> p.count
4
>>> p.num_pages
2
>>> page1 = p.page(1)
>>>
>>> page1.previous_page_number()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Users\Rick\ws2\env\lib\site-packages\django\core\paginator.py", line 136
, in previous_page_number
return self.paginator.validate_number(self.number - 1)
File "C:\Users\Rick\ws2\env\lib\site-packages\django\core\paginator.py", line 38,
in validate_number
raise EmptyPage('That page number is less than 1')
django.core.paginator.EmptyPage: That page number is less than 1
>>>
According to the previous_page_number() documentation.
Returns the previous page number. Raises InvalidPage if previous page doesn’t exist.
I was expecting previous_page_number() to raise InvalidPage exception as documentation says.
Change History (3)
comment:1 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 9 years ago
comment:3 by , 9 years ago
| Resolution: | → invalid |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
because
EmptyPageis subclass ofInvalidPage.You can catch
EmptyPageandPageNotAnIntegerusing their super classInvalidPage