관리 메뉴

Silver Library (Archived)

Django get_page vs page 본문

Personal DB/Unclassified record

Django get_page vs page

Ayin Kim 2020. 12. 21. 12:13
반응형

Unlike other language does function like 

function():

 

in Django, this sounds like:

{% if something.has_previous %}

 

no (bracket), nor colon

 

+

except Exception stead, 

using Exception such like exception EmptyPage is better to use. => in order to return when a specific error occurred, targeting response to the error is better. (stead of Excepting all equally).

 

*Why doing this?

To prevent a troll user to do some ugly thing with URL.

 

+

Paginator.orphans

Optional. Use this when you don’t want to have a last page with very few items. If the last page would normally have a number of items less than or equal to orphans, then those items will be added to the previous page (which becomes the last page) instead of leaving the items on a page by themselves. For example, with 23 items, per_page=10, and orphans=3, there will be two pages; the first page with 10 items and the second (and last) page with 13 items. orphans defaults to zero, which means pages are never combined and the last page may have one item.

---------

Methods

--------------------

Paginator.get_page(number)

Returns a Page object with the given 1-based index, while also handling out of range and invalid page numbers.

If the page isn’t a number, it returns the first page. If the page number is negative or greater than the number of pages, it returns the last page.

Raises an EmptyPage exception only if you specify Paginator(..., allow_empty_first_page=False) and the object_list is empty.

-------------------------

Paginator.page(number)

Returns a Page object with the given 1-based index. Raises InvalidPage if the given page number doesn’t exist.