django视图集扩展了mixins.UpdateModelMixin,但邮递员通过补丁方法更新模型会返回'详细信息:不允许使用方法PATCH'

时间:2018-10-08 08:37:16

标签: python django django-rest-framework

视图集代码

class UserTitleViewset(mixins.ListModelMixin, mixins.RetrieveModelMixin, mixins.CreateModelMixin,
                       mixins.UpdateModelMixin, viewsets.GenericViewSet):

    queryset = UserTitleMod.objects.all()
    serializer_class = UserTitleSerializer

    def update(self, request, *args, **kwargs):
        return "ok"

    def perform_update(self, serializer):
        return "ok"

settings.py

CORS_ALLOW_METHODS = [
    'GET',
    'POST',
    'PUT',
    'PATCH',
    'DELETE',
    'OPTIONS'
]

我已经尝试了很多次,但是仍然无法正常工作。谢谢您的答复。

0 个答案:

没有答案