覆盖
get_paginated_response您的分页类的方法,并且不包括计数。您可以参考该类的基本实现,
PageNumberPagination以查看应返回的内容。
from rest_framework.pagination import PageNumberPaginationfrom collections import OrderedDict # requires Python 2.7 or laterclass PageNumberPaginationWithoutCount(PageNumberPagination): # Set any other options you want here like page_size def get_paginated_response(self, data): return Response(OrderedDict([ ('next', self.get_next_link()), ('previous', self.get_previous_link()), ('results', data) ]))然后在中
settings.py,设置
DEFAULT_PAGINATION_CLASS为新的分页类别。
DEFAULT_PAGINATION_CLASS = 'path.to.PageNumberPaginationWithoutCount'
分页文档中的示例中使用了这种方法。
编辑: 从下面的注释中听起来这可能不足以防止缓慢的sql查询,因此您可能还需要覆盖
paginate_queryset。



