22 lines
708 B
Python
22 lines
708 B
Python
from rest_framework.pagination import PageNumberPagination
|
|
from rest_framework.response import Response
|
|
|
|
|
|
class StandardResultsSetPagination(PageNumberPagination):
|
|
"""标准分页器"""
|
|
page_size = 20
|
|
page_size_query_param = 'page_size'
|
|
max_page_size = 100
|
|
|
|
def get_paginated_response(self, data):
|
|
"""自定义分页响应格式"""
|
|
return Response({
|
|
"code": 200,
|
|
"message": "获取数据成功",
|
|
"data": {
|
|
"count": self.page.paginator.count,
|
|
"next": self.get_next_link(),
|
|
"previous": self.get_previous_link(),
|
|
"results": data
|
|
}
|
|
}) |