django - 尝试使用 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')
解决方案
推荐阅读
- azure - 将 SAS 令牌重写(附加)到 azure cdn 中的 url
- python - 使用 Galaxy Zoo 数据集、TensorFlow 和 Keras 训练 GAN
- angular - Angular 11 - google-maps 切换地图样式
- angular - 更改服务对象甚至替换原始对象
- r - 如何使用 R 中的查看功能查看特定的 ID 号?
- xml - 在 Xamarin Android 中使用 TabbedPage.ToolbarPlacement=“Bottom”时如何更改 TabBar 字体系列?
- python - 如何在 discord.py 中设置位置参数
- javascript - 使用 MongoDB/JavaScript 在 Docker 中自动创建数据库/表的问题
- html - 使容器调整其宽度,直到文本填满可用高度
- r - 在具有更新角色条件的 R 配方中不起作用