自定义分页的类,继承 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. linux密码暴力破解机

    linux 密码保存在 /etc/shadow shadow 文件的保存格式 python:$$mWSyC6Pv$hpMreQT77R9ML/Xx1QnRAow1tUTDjIowaTssV7bZw9S ...

  2. Selenium Webdriver概述(转)

    Selenium Webdriver https://www.yiibai.com/selenium/selenium_overview.html# webdriver自动化俗称Selenium 2. ...

  3. 支付宝app支付服务端流程

    支付宝APP支付服务端详解 前面接了微信支付,相比微信支付,支付宝APP支付提供了支付封装类,下面将实现支付宝APP支付.订单查询.支付结果异步通知.APP支付申请参数说明,以及服务端返回APP端发起 ...

  4. 前后端分离之JWT用户认证(转)

    在前后端分离开发时为什么需要用户认证呢?原因是由于HTTP协定是不储存状态的(stateless),这意味着当我们透过帐号密码验证一个使用者时,当下一个request请求时它就把刚刚的资料忘了.于是我 ...

  5. 一个轻巧高效的多线程c++stream风格异步日志(一)

    一个轻巧高效的多线程c++stream风格异步日志 一个轻巧高效的多线程c++stream风格异步日志 前言 功能需求 性能需求 Logger实现 LogStream类 Logger类 LogStre ...

  6. Redis指令与数据结构(二)

    0.Redis目录结构 1)Redis介绍及部署在CentOS7上(一) 2)Redis指令与数据结构(二) 3)Redis客户端连接以及持久化数据(三) 4)Redis高可用之主从复制实践(四) 5 ...

  7. Java日期和时间

    目录 Java 日期和时间 Java 日期和时间 学习自 http://blog.csdn.net/zjf280441589/article/details/50447533 Date类 Date 类 ...

  8. 【BZOJ 1211】 1211: [HNOI2004]树的计数 (prufer序列、计数)

    1211: [HNOI2004]树的计数 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2468  Solved: 868 Description 一 ...

  9. 5969 [AK]刻录光盘

    题目描述 Description • 在FJOI2010夏令营快要结束的时候,很多营员提出来要把整个夏令营期间的资料刻录成一张光盘给大家,以便大家回去后继续学习.组委会觉得这个主意不错!可是组委会一时 ...

  10. codevs 3022 西天收费站

    题目描述 Description 唐僧师徒四人终于发现西天就在眼前,但猴子突然发现前面有n个收费站(如来佛太可恶),在每个收费站用不同的方式要交的钱不同,输入每个收费站的每种方法收的钱,输出最少花的钱 ...