django-drf

分页

rest_frameworksettings PAGE_SIZE:None   默认没有配置分页
需要在settings.py 配置
接口返回数据,会给上一页下一页
REST_FRAMEWORK={
  'PAGE_SIZE':2,
}
# 查所有,才需要分页
from rest_framework.generics import ListAPIView
# 内置三种分页方式
from rest_framework.pagination import PageNumberPagination,LimitOffsetPagination,CursorPagination
PageNumberPagination
    page_size:每页显示的条数
    page_query_param='page'  前端发送的页数关键字名,默认为'page'
    max_query_size=5     前端最多能设置的每页数量
  
class BookView(ListAPIView):
      queryset=models.Book.objects.all()
      serializer_class=BookModelSerializer
      # 配置分页
      pagination_class= MyPageNumberPagination
      
微信:jinmuqq222
原文地址:https://www.cnblogs.com/jinmuqq222/p/14603594.html