Opened 8 years ago

Closed 8 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 Pat, 8 years ago

Owner: changed from nobody to Pat
Status: newassigned

comment:2 by kapil garg, 8 years ago

because EmptyPage is subclass of InvalidPage.

You can catch EmptyPage and PageNotAnInteger using their super class InvalidPage

comment:3 by kapil garg, 8 years ago

Resolution: invalid
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top