rest framework错误笔记——AssertionError: Cannot apply DjangoModelPermissionsOrAnonReadOnly on a view that does not set `.queryset` or have a `.get_queryset()` method.
用到@api_view装饰器时,访问路由查看api数据时,报错:
AssertionError: Cannot apply DjangoModelPermissionsOrAnonReadOnly on a view that does not set `.queryset` or have a `.get_queryset()` method.
按照官网教程(http://www.django-rest-framework.org/),在settings文件里写入的设置为
REST_FRAMEWORK = { # Use Django's standard `django.contrib.auth` permissions, # or allow read-only access for unauthenticated users. 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' ] }
将设置里的'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'一句删除,重启项目再次访问,不在报错。
注:'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'适用于添加身份验证和权限以后。