传参 按照参数分页 不传返回全部
核心代码:
from rest_framework.pagination import PageNumberPagination
class PageNum(PageNumberPagination):
page_size_query_param = 'page_size'
page_query_param = 'page'
class getuserlist(APIView):
def get(self, request):
queryset = userlist.objects.all()
print(request)
if request.GET.get('page'):
print(queryset)
pg = PageNum()
page_objs = pg.paginate_queryset(queryset=queryset, request=request, view=self)
ser = sergetuserList(instance=page_objs, many=True)
return Response(ser.data)
ser = sergetuserList(instance=queryset, many=True)
return Response(ser.data)
|