restframework 使用CustomPageNumberPagination实现分页
作者:互联网
from rest_framework.pagination import PageNumberPagination class CustomPageNumberPagination(PageNumberPagination): # page_query_param = "" # 地址上面代表页码的变量名,默认为page page_size = 5 # 每一页显示的数据量,没有设置页码,则不进行分页 # 允许客户端通过指定的参数名来设置每一页数据量的大小,默认是size page_size_query_param = "size" max_page_size = 20 # 限制每一页最大展示的数据量
class CourseListApiView(ListAPIView): # 指定过滤和排序类 filter_backends = [DjangoFilterBackend, OrderingFilter, ] # 指定过滤字段 filter_fields = ('course_category',) # 指定排序字段 ordering_fields = ('id', 'students', 'price') queryset = Course.objects.filter(is_show=True).order_by('orders', '-id') serializer_class = CourseSerializer pagination_class = CustomPageNumberPagination
测试
标签:分页,CustomPageNumberPagination,page,filter,restframework,数据量,class,size 来源: https://www.cnblogs.com/wtil/p/14965153.html