Django中使用Pagination的分页范例源码
將做工程過程重要的內(nèi)容做個珍藏,下面代碼內(nèi)容是關(guān)于Django中使用Pagination的分頁范例的代碼。
from django.core.paginator import Paginator
objects = ['john', 'paul', 'george', 'ringo']
p = Paginator(objects, 2)
p.count
4
p.num_pages
2
p.page_range
[1, 2]
page1 = p.page(1)
page1
<Page 1 of 2>
page1.object_list
['john', 'paul']
page2 = p.page(2)
page2.object_list
['george', 'ringo']
page2.has_next()
False
page2.has_previous()
True
page2.has_other_pages()
True
page2.next_page_number()
Traceback (most recent call last):
...
EmptyPage: That page contains no results
page2.previous_page_number()
1
page2.start_index() # The 1-based index of the first item on this page
3
page2.end_index() # The 1-based index of the last item on this page
4
p.page(0)
Traceback (most recent call last):
...
EmptyPage: That page number is less than 1
p.page(3)
Traceback (most recent call last):
...
EmptyPage: That page contains no results
轉(zhuǎn)載于:https://blog.51cto.com/14142860/2345322
總結(jié)
以上是生活随笔為你收集整理的Django中使用Pagination的分页范例源码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ubuntu下selenium+Chro
- 下一篇: python设计自定义函数_python