Loading

关于drf分页url参数params

image

page和size

from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class MinePageNumberPagination(PageNumberPagination):
    page_size_query_param = 'size'  # 允许通过查询参数指定每页条数
    max_page_size = 150

    def get_paginated_response(self, data):
        return Response({
            'count': self.page.paginator.count,
            'page_size': self.request.query_params.get('size', self.page_size),
            'results': data,
        })


posted @ 2024-10-15 10:57  一只大学生  阅读(4)  评论(0编辑  收藏  举报