Django Rest 框架分页覆盖
Django Rest Framework Pagination Overriding
我想我正在建立一个全局分页设置并在基本视图集中覆盖它,但这似乎并没有发生。
在我的设置中,我有:
REST_FRAMEWORK = {
'PAGINATE_BY': 10
}
但在我的视图中我有
class MyViewSet(viewsets.ReadOnlyModelViewSet):
""" DRF endpoint. """
queryset = MyModel.objects.all()
paginate_by = None # Note this guy right here
serializer_class = MySerializer
lookup_field = 'my_id'
filter_backends = (filters.SearchFilter,)
search_fields = ('name',)
当我到达终点时,我得到 10 秒的分页。这不是正确的做法吗?
使用 None
作为值与根本不设置 paginate_by
属性具有相同的效果。看看 DRF 的 the code。您必须在那里设置一个明确的值才能生效。
不过,只要我们在主题上,'PAGINATE_BY'
全局设置 will soon be deprecated in favor of 'PAGE_SIZE'
, and the per-view paginate_by
class attribute should be replaced with a custom paginator subclass。
我想我正在建立一个全局分页设置并在基本视图集中覆盖它,但这似乎并没有发生。
在我的设置中,我有:
REST_FRAMEWORK = {
'PAGINATE_BY': 10
}
但在我的视图中我有
class MyViewSet(viewsets.ReadOnlyModelViewSet):
""" DRF endpoint. """
queryset = MyModel.objects.all()
paginate_by = None # Note this guy right here
serializer_class = MySerializer
lookup_field = 'my_id'
filter_backends = (filters.SearchFilter,)
search_fields = ('name',)
当我到达终点时,我得到 10 秒的分页。这不是正确的做法吗?
使用 None
作为值与根本不设置 paginate_by
属性具有相同的效果。看看 DRF 的 the code。您必须在那里设置一个明确的值才能生效。
不过,只要我们在主题上,'PAGINATE_BY'
全局设置 will soon be deprecated in favor of 'PAGE_SIZE'
, and the per-view paginate_by
class attribute should be replaced with a custom paginator subclass。