Unexpected exception raised by previous_page_number() method - Django Paginator -


>>> 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 less 1') django.core.paginator.emptypage: page number less 1 >>> 

according previous_page_number() documentation.

page.previous_page_number()

returns previous page number. raises invalidpage if previous page doesn’t exist.

i expecting previous_page_number() raise invalidpage exception documentation says. why returning emptypage exception ?

am missing ?

according paginator source(django.core.paginator.py) in 1.10:

def validate_number(self, number):     """     validates given 1-based page number.     """     try:         number = int(number)     except (typeerror, valueerror):         raise pagenotaninteger('that page number not integer')     if number < 1:         raise emptypage('that page number less 1')     if number > self.num_pages:         if number == 1 , self.allow_empty_first_page:             pass         else:             raise emptypage('that page contains no results')     return number 

as per condition: number less 1 raise

emptypage('that page number less 1')

but according django docs should have raised base exception invalidpage !

this might typo mistake while writing documentation previous_page_number()

but per invalidpage explanation, emptypage exception comes under only. nothing detailed/derived exception of invalidpage.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -