1.github搜索 pure pagination
2.找到
3.pip install django-pure-pagination
4.setting.py中配置app
#分页 'pure_pagination',5.setting.py中配置:
#分页 PAGINATION_SETTINGS = { 'PAGE_RANGE_DISPLAYED': 10, 'MARGIN_PAGES_DISPLAYED': 2, 'SHOW_FIRST_PAGE_WHEN_INVALID': True, }6.Views.py中对需要进行分页的数据进行处理:
# 分页 from django.shortcuts import render_to_response from pure_pagination import Paginator, EmptyPage, PageNotAnInteger
#分页 try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 p = Paginator(all_orgs,5, request=request) orgs = p.page(page)
return render(request,'org-list.html',{ 'all_orgs':orgs,)}其中p = Paginator(all_orgs,5,request=request),中的5为每页展示的数据,官方文档中有缺陷,并没有这个number。
7.前段显示数据:
{% for course_org in all_orgs.object_list %} ... {% endfor %}8.自带的分页样式:
{{ people.render }}9.一般用自定义分页样式:
<div class="pageturn"> <ul class="pagelist"> {% if all_orgs.has_previous %} <li class="long"><a href="?{{ all_orgs.previous_page_number.querystring }}">上一页</a></li> {% endif %} {% for page in all_orgs.pages %} {% if page %} {% ifequal page all_orgs.number %} <li class="active"><a href="?{{ page.querystring }}">{{ page }}</a></li> {% else %} <li><a href="?{{ page.querystring }}" class="page">{{ page }}</a></li> {% endifequal %} {% else %} <li class="none"><a href="">...</a></li> {% endif %} {% endfor %} {% if all_orgs.has_next %} <li class="long"><a href="?{{ all_orgs.next_page_number.querystring }}">下一页</a></li> {% endif %} </ul> </div>10.最终效果: