您好,登录后才能下订单哦!
将做工程过程重要的内容做个珍藏,下面代码内容是关于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
4p.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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。