分页封装
封装:course/utils.py
from rest_framework.pagination import PageNumberPagination
class CoursePageNumberPagination(PageNumberPagination):
"""课程列表数据的分页器"""
page_query_param = "page" # 页码参数
page_size_query_param = 'page_size' # 单页数据量
page_size = 5 # 默认的单页数据量,就是每一页显示5个课程信息
max_page_size = 20 # 允许客户端设置的单页数据量
视图:course/views.py
from .utils import CoursePageNumberPagination
class CourseAPIView(ListAPIView):
"""课程列表接口"""
queryset = Course.objects.filter(is_delete=False, is_show=True).order_by("-orders")
serializer_class = CourseSerializer
pagination_class = CoursePageNumberPagination
接口
http://127.0.0.1:8000/course/