默认LimitOffsetPagination在DRF3.0.4中不起作用

时间:2019-07-02 05:29:31

标签: pagination django-rest-framework django-1.7

基本的LimitOffsetPagination在django 1.7.11和rest-framework3.0.4中不起作用。代码如下所示。这是否支持默认的LimitOffsetPagination?

请帮助我。。谢谢。

settings.py

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',
    ),
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
    'PAGE_SIZE': 10,
}
urls.py

from django.conf.urls import include, patterns, url
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register(r'sample', views.SampleViewSet)

urlpatterns = [
    url('', include(router.urls)),
]

views.py

class SampleViewSet(viewsets.ModelViewSet):
    serializer_class = SampleSerializer
    queryset = Sample.objects.all()


serializers.py

class SampleSerializer(serializers.ModelSerializer):
    image = serializers.ReadOnlyField(source='photo_o.url')

    class Meta:
        model = Sample
        fields = ('id','name','slug''image',)

预期输出如下: {     “计数”:1023     “ next”:“ https://api.example.org/accounts/?limit=100&offset=500”,     “ previous”:“ https://api.example.org/accounts/?limit=100&offset=300”,     “结果”:[        …     ] }

0 个答案:

没有答案