关闭Django Rest Framework ModelViewSet的自动分页 [英] Turn off automatic pagination of Django Rest Framework ModelViewSet

查看:248
本文介绍了关闭Django Rest Framework ModelViewSet的自动分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将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的自动分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆