我有一个viewset
子类modelviewset
,我添加下一个:
authication_classes = [SessionAuthentication,BasicAuthentication]
permission_classes = [IsAuthenticated]
然后,在列出、详细信息/检索和提出请求时收到以下消息。
"detail": "未提供身份验证凭据。"
当我更新数据时,我应该改变什么来只给出这个消息?
我有一个viewset
子类modelviewset
,我添加下一个:
authication_classes = [SessionAuthentication,BasicAuthentication]
permission_classes = [IsAuthenticated]
然后,在列出、详细信息/检索和提出请求时收到以下消息。
"detail": "未提供身份验证凭据。"
当我更新数据时,我应该改变什么来只给出这个消息?
覆盖类get_permissions
的方法ModelViewSet
。
示例:
class FooViewSet(ModelViewSet):
authentication_classes = (SessionAuthentication, BasicAuthentication, )
permission_classes = (IsAuthenticated, )
def get_permissions(self):
if self.request.method != 'PUT':
return []
return super().get_permissions()