安装

pip install django-pure-pagination
具体步骤搜索GitHub里面详情。
class OrgView(View):
    """
        课程机构列表功能
    """

    def get(self, request):
    
        all_orgs = CourseOrg.objects.all()  # 课程机构
        org_nums = all_orgs.count()  # 记录多少家
        # 城市
        all_citys = CityDict.objects.all()        # 课程机构进行分页
        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,            "all_citys": all_citys,            'org_nums': org_nums,
        })
通过传过来的orgs,自动生成页脚
{#  分页#}
                    
                        
                            {#  如果有,获取上一页 #}
                            {% if all_orgs.has_previous %}
                                上一页
                            {% endif %}
                            
                            {# 判断剩余页面的显示方法: #}
                            {% for page in all_orgs.pages %}
                            
                                {% if page %}
                                
                                    {# 判断page和 all_orgs.number是否相等 : }
                                    {% ifequal page all_orgs.number %}
                                        {{ page }}
                                    {% else %}
                                        
  • {{ page }}
  •                                     {% endifequal %}                                 {% else %}                                     ...                                 {% endif %}                             {% endfor %}                                                          {#  如果有,获取下一页 #}                             {% if all_orgs.has_next %}                                 下一页                             {% endif %}                                                                           

    总结

    切记:做分页获取数据要调用 .object_list
    {% for course_org in all_orgs.object_list %}