自定义分页的类,继承 PageNumberPagination

class StandardResultsSetPagination(PageNumberPagination):
page_size =
page_size_query_param = 'page_size'
max_page_size =

在某个视图下应用自定义分页类

class BillingRecordsView(generics.ListAPIView):
queryset = Billing.objects.all()
serializer_class = BillingRecordsSerializer
pagination_class = LargeResultsSetPagination

或者全局应用自定义分页类

REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'apps.core.pagination.StandardResultsSetPagination'
}

配置含义

The PageNumberPagination class includes a number of attributes that may be overridden to modify the pagination style.

To set these attributes you should override the PageNumberPagination class, and then enable your custom pagination class as above.

    django_paginator_class - The Django Paginator class to use. Default is django.core.paginator.Paginator, which should be fine for most use cases.
page_size - A numeric value indicating the page size. If set, this overrides the PAGE_SIZE setting. Defaults to the same value as the PAGE_SIZE settings key.
page_query_param - A string value indicating the name of the query parameter to use for the pagination control.
page_size_query_param - If set, this is a string value indicating the name of a query parameter that allows the client to set the page size on a per-request basis. Defaults to None, indicating that the client may not control the requested page size.
max_page_size - If set, this is a numeric value indicating the maximum allowable requested page size. This attribute is only valid if page_size_query_param is also set.
last_page_strings - A list or tuple of string values indicating values that may be used with the page_query_param to request the final page in the set. Defaults to ('last',)
template - The name of a template to use when rendering pagination controls in the browsable API. May be overridden to modify the rendering style, or set to None to disable HTML pagination controls completely. Defaults to "rest_framework/pagination/numbers.html".

可以自定义每页多少数据,第几页等参数,这样前端把第几页、每页多少数据传给后台django应用,就可以获得相应的数据

来自:https://www.django-rest-framework.org/api-guide/pagination/

参考:

https://docs.djangoproject.com/en/2.2/topics/pagination/

利用rest-framework实现django应用的分页功能的更多相关文章

  1. 利用Bootstrap Paginator插件和KnockoutJS完成分页功能

    在最近一个项目中,需要结合一堆条件查询并对查询的结果数据完成一个简单分页功能,可是做着做着,自己的思路越来越模糊,做到心态崩溃!!! 哈哈,特此花点时间重新总结,并从最简单的分页,然后向多条件查询分页 ...

  2. Django实现简单分页功能

    使用django的第三方模块django-pure-pagination 安装模块: pip install django-pure-pagination 将'pure_pagination'添加到s ...

  3. Django自定制分页功能

    URL: """django_paginner URL Configuration The `urlpatterns` list routes URLs to views ...

  4. Django 之 Paginator 分页功能

    Django Paginator Django 分页官方文档  https://docs.djangoproject.com/en/1.10/topics/pagination/ 此分页方法没有限制显 ...

  5. 【原】django实现列表分页功能

    在view.py里添加分页查询方法: from django.http import JsonResponse from django.views.decorators.http import req ...

  6. Django,ajax实现表格增删查改,Django内置分页功能。

    1.工程目录 2.urls.py """Django_ajax URL Configuration The `urlpatterns` list routes URLs ...

  7. django网页的分页功能,大家如果有疑问请留言

    url文件 from django.contrib import admin from django.conf.urls import url from app01 import views urlp ...

  8. django内置分页功能扩展

    实现自定制页码数类型class myPaginator(Paginator): def __init__(self,curr_page,per_page_num,*args,**kwargs): se ...

  9. django之快速分页

    本文介绍djanog两种分页,第一是普通分页,第二是使用haystack全文检索的分页. 1.django自带分页功能,这个功能非常好用.基本知识点:Django提供了数据分页的类,这些类被定义在dj ...

随机推荐

  1. homestead 无法被局域网其他电脑局域网访问解决办法

    修改(该文件就是通过git下载的homestead文件夹中的文件) homestead/scripts/homestead.rb   # Configure A Private Network IP ...

  2. 【noip模拟赛3】拣钱

    描述 最近,Henry由于失恋(被某大牛甩掉!)心情很是郁闷.所以,他去了大牛家,寻求Michael大牛的帮助,让他尽快从失恋的痛苦中解脱出来.Michael大牛知道Henry是很爱钱的,所以他是费尽 ...

  3. 【noip模拟赛3】编码

    描述 Alice和Bob之间要进行秘密通信,他们正在讨论如何对信息进行加密: Alice:“不如采用一种很简单的加密方式:’A’替换成1,’B’替换成2,„„,’Z’替换成26.” Bob:“这种加密 ...

  4. 常用的服务发现对比(Consul、zookeeper、etcd、eureka)

    这里就平时经常用到的服务发现的产品进行下特性的对比,首先看下结论:   Feature Consul Zookeeper Etcd Eureka 服务健康检查  服务状态,内存,硬盘等  (弱)长连接 ...

  5. SDC_ETL融合数据产品白皮书

    SDC_ETL融合数据产品白皮书 http://www.sefonsoft.com/?s=/home/pro/pdf/id/48.html

  6. 如何将你的github仓库部署到github pages

    很多时候我都在思考一个问题,我们每天遇到各种各样的问题,然后我们需要不断google.百度,达到我们解决问题的目的.但是在这个过程中,我们总是能够见到,对于同一个问题,总是有大量错误.copy的博客. ...

  7. leetcode 每个结点的右指针 python

    每个节点的右向指针     给定一个二叉树 struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *n ...

  8. 解决浏览器抛出乱码,(HTML、PHP等的乱码问题)

    在Windows上编写html或php代码的时候,本地编辑器设置的文件编码格式是utf-8保存,但是浏览器打开页面的时候经常出现乱码,而且浏览器自动检测到的页面编码为GBK格式,这时候我就开始纳闷了? ...

  9. 使用Puppeteer进行数据抓取(三)——简单的示例

    本文以一个示例简单的介绍一下puppeteer的用法,我们的目的是:获取我博客上的文章的前十页的所有随笔的标题和链接.由于puppeteer本身是自动化chorme,因此这里我们的步骤和手动操作浏览器 ...

  10. MySQL编码latin1转utf8

    mysql移植含有中文的数据时,很容易出现乱码问题.很多是在从mysql4.x向mysql5.x移植的时候出现.mysql的缺省字符集是 latin1,在使用mysql4.x的时候,很多人都是用的la ...