首页 > 解决方案 > 尝试使用 UpdateAPIView 进行部分更新时出现错误请求 400

问题描述

我正在使用 DRF UpdateAPIView 采用 PATCH 方法并部分更新我的模型。默认情况下,它应该正确处理部分更新,但我以某种方式收到错误请求错误。这里可能有什么问题?

看法:

class ProfileViewUpdate(generics.UpdateAPIView):
    queryset = Profile.objects.all()
    serializer_class = ProfileSerializer
    lookup_field = 'token'
    lookup_url_kwarg = 'pk'

    def partial_update(self, request, *args, **kwargs):
        kwargs['partial'] = True
        return self.update(request, *args, **kwargs)

序列化器:

class ProfileSerializer(serializers.ModelSerializer):
    class Meta:
        model = Profile
        fields = ('token', 'bio', 'name', 'email', 'sport', 'location', 'image')

标签: djangodjango-modelsdjango-rest-frameworkmodelserialization

解决方案


推荐阅读