问题描述
我将Django Rest Framework的ModelViewSet
用于我的其中一个视图. ModelViewSet
使用ListModelMixin
会自动对结果进行分页,但是我不希望对结果进行分页.在我的API调用中,我说了要返回多少结果,但按目前的情况,一次调用最多不能返回10个结果.
I am using Django Rest Framework's ModelViewSet
for one of my views. ModelViewSet
uses the ListModelMixin
which automatically paginates the results but I do not want the results paginated. In my API call I say how many results I want returned but as it stands I can't get back more than 10 results in one call.
有没有办法关闭自动分页功能,所以我可以得到想要返回的尽可能多的结果?
Is there a way to turn off the automatic pagination and so I can have as many results as I want returned?
推荐答案
如果使用的是DRF的最新版本,则只需在ModelViewSet
定义中添加pagination_class = None
.
If you are using recent versions of DRF you just need to add pagination_class = None
to your ModelViewSet
definition.
class MyClassBasedView(ModelViewSet):
pagination_class = None
...
您还可以在此处看到一些提示 https://github.com/tomchristie /django-rest-framework/issues/1390
You also can see some tips here https://github.com/tomchristie/django-rest-framework/issues/1390
这篇关于关闭Django Rest Framework ModelViewSet的自动分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!