django分页相关类
来源:互联网 发布:淘宝小型高音收录放机 编辑:程序博客网 时间:2024/06/01 10:08
主要参照了django的官方文档
Paginator 类¶
构造函数:
Paginator(object_list, per_page, orphans=0, allow_empty_first_page=True)
必传参数¶
- object_list
- 一个list,tuple,django的QuerySet,或者拥有``count()``和``__len__()``方法的可分解对象。
- per_page
- 每一页最大的对象个数。
可选参数¶
- orphans
- The minimum number of items allowed on the last page, defaults to zero.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 equalto orphans, then those items will be added to the previous page (whichbecomes the last page) instead of leaving the items on a page bythemselves. For example, with 23 items, per_page=10, andorphans=3, there will be two pages; the first page with 10 items andthe second (and last) page with 13 items.
- allow_empty_first_page
- Whether or not the first page is allowed to be empty. If False andobject_list is empty, then an EmptyPage error will be raised.
方法¶
Paginator.page(number)
根据索引number,返回一个’Page’对象,如果不存在,引起 InvalidPage异常
属性¶
Paginator.count
所有对象的总数, 尝试通过``object_list.count()``和``object_list.__len__()``取得
Paginator.num_pages
总共的页数
Paginator.page_range
页的范围,比如 [1, 2, 3, 4] 。
InvalidPage 异常¶
当页面不存在或者无效时,会引起``InvalidPage``异常,一般这个异常就够用,如果需要更详细信息,请查阅官方文档。还有``PageNotAnInteger``,``EmptyPage``可用
Page 类¶
Page(object_list, number, paginator):
一般不需用户自己构造,通过`Paginator.page` 生成。
方法¶
Page.has_next()
如果下一页存在,返回True。
Page.has_previous()
如果前一页存在返回 True
Page.has_other_pages()
如果上一页面或者下一页存在,返回``True``
Page.next_page_number()
返回下一页的索引,这个函数比较傻(不管下一页是否存在,都是简单的+1)
Page.previous_page_number()
返回上一页的索引,其他同上
Page.start_index()
返回当前页,第一个对象的索引。
Page.end_index()
道理同上。
属性¶
Page.object_list
当前页对象列表
Page.number
当前页的索引
Page.paginator
和page相关的分页类
- django分页相关类
- django 分页
- django分页
- django 分页
- django 分页
- Django分页
- django分页
- Django 分页
- Django 分页
- django分页
- django 分页
- Django 分页
- Django分页
- Django 分页
- Django 分页 django-pagination
- django分页(原生分页)
- Django相关
- Django相关
- Python之旅
- c摘要
- One编程组logo
- PHP简介
- VB.Net程序设计:自动运行任务计划
- django分页相关类
- 常用网站收集
- 一个简单的3D立方体C++源码
- 开心图:群里该找哪位?
- js中对象转到c#对象方法
- 一些决定
- 一切都那么突然,一切都那么自然
- membership连接自定义数据库或都是把它从app_data里换其它地方以下的都需要,再也不会连不上数据库了
- 利用WatiN自动化网站功能测试
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
机械放线架
放线菌观察
电动放线架
光缆放线架
内氏放线菌
电力放线架
电工放线架
卧式放线盘
放线盘图片
放线车
放线架子
放线器
工地放线
怎么放线
放线吧
放线仪器
放线图片
放线测量
工程放线
建筑放线
电缆放线车
水准仪放线
全站仪放线
光缆放线车
经纬仪放线
装修放线
放线架厂家
放线工具
放线飞行器
基础放线
电缆放线机
gps放线
定位放线
弧形放线
如何放线
道路放线
楼层放线
电工放线器
光缆放线盘
怎样放线
自动放线器