Django rest framework: how to turn off/on pagination in ModelViewSet

前端 未结 2 1232
广开言路
广开言路 2021-02-15 07:40

I\'m using Django REST framework with djangorestframework-csv with default pagination settings, but when request is with format \"CSV\", there is no need in paginaion. Is possib

2条回答
  •  灰色年华
    2021-02-15 08:03

    One option would be to dynamically disable pagination on the view by setting a no_page query parameter:

    def paginate_queryset(self, queryset, request, view=None):
        if 'no_page' in request.query_params:
            return None
    
        return super().paginate_queryset(queryset, request, view)
    

提交回复
热议问题