车陂IT仔
2022-04-20 12:00
采纳率: 0%
浏览 22
已结题

django rest_framework如何在get_paginated_response方法中返回url传入的每页展示的条数(page_size)

我重写了方法get_paginated_response,返回总条数、当前页面已经总页码,那么这么返回这个url(?/size=2)中的size呢

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


class PageNumber(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'size'
    page_query_param = 'page'
    max_page_size = None

    # 重写方法,去掉next等字段,自定义返回
    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('total', self.page.paginator.count),
            ('total_page', self.page.paginator.num_pages),
            ('page', self.page.number),
            # 这个是我疑问的地方
            ('size', ???),
            ('list', data),
        ]))

1条回答 默认 最新

相关推荐 更多相似问题