django 分页django-pure-pagination
django 分页 pure Pagination
2023-09-27 14:26:13 时间
虽然django自带了一个paginator,但不是很方便,我们使用django-pure-pagination
github地址https://github.com/jamespacileo/django-pure-pagination.git
里面有教程,这里简要的说明一下
第一步下载
两种方式
一pip安装pip install django-pure-pagination
二源码安装git clone https://github.com/jamespacileo/django-pure-pagination.git
cd django-pure-pagination
python setup.py install
两者选其一
第二步使用
在settings中添加
INSTALLED_APPS = ( ... 'pure_pagination', )
这里在settings中加入一些分页配置,
PAGINATION_SETTINGS = { 'PAGE_RANGE_DISPLAYED': 10, 'MARGIN_PAGES_DISPLAYED': 2, 'SHOW_FIRST_PAGE_WHEN_INVALID': True, }
views
# views.py from django.shortcuts import render_to_response from pure_pagination import Paginator, EmptyPage, PageNotAnInteger def index(request): try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 objects = ['john', 'edward', 'josh', 'frank'] # Provide Paginator with the request object for complete querystring generation p = Paginator(objects, request=request) people = p.page(page) return render_to_response('index.html', { 'people': people, }
html
{# index.html #} {% extends 'base.html' %} {% block content %} {% for person in people.object_list %} <div> First name: {{ person }} </div> {% endfor %} {# The following renders the pagination html #} <div id="pagination"> {{ people.render }} </div> {% endblock %}
还有什么不明白的可以上github上看
相关文章
- Django rest framework(7)----分页
- django之异常错误3(Student matching query does not exist.)
- django之创建第8个项目-数据库配置及同步研究
- 「基于Python技术的智慧中医商业项目」Django前端系统配置
- Django实现CMS内容管理系统mptt评论功能
- python django 基本测试 及调试 201812
- Django+Bootstrap+Mysql 搭建个人博客 (六)
- 3.django Model
- 【Jenkins自动化部署】Windows节点Apache+Django服务自动化构建
- Django:如何给文章列表添加图片
- ajax方式上传图片到Django后台
- Django:查询后,分页功能为全部对象分页,丢失查询查询参数
- Django学习路7_注册app到能够在页面上显示app网页内容
- 【django学习】——Django介绍和实战(开发简易版博客网页)
- Django之模型类详解(七)
- [Django] Django项目创建