本文共 925 字,大约阅读时间需要 3 分钟。
将做工程过程重要的内容做个珍藏,下面代码内容是关于Django中使用Pagination的分页范例的代码。
from django.core.paginator import Paginator
objects = ['john', 'paul', 'george', 'ringo']p = Paginator(objects, 2)p.count
4p.num_pages2p.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()Falsepage2.has_previous()Truepage2.has_other_pages()Truepage2.next_page_number()Traceback (most recent call last):...EmptyPage: That page contains no resultspage2.previous_page_number()1page2.start_index() # The 1-based index of the first item on this page3page2.end_index() # The 1-based index of the last item on this page4p.page(0)
Traceback (most recent call last):...EmptyPage: That page number is less than 1p.page(3)Traceback (most recent call last):...EmptyPage: That page contains no results
转载于:https://blog.51cto.com/14142860/2345322