为了账号安全,请及时绑定邮箱和手机立即绑定

Django Rest Framework:序列化器响应错误

Django Rest Framework:序列化器响应错误

临摹微笑 2021-09-25 13:29:33
我在 DRF 中的视图集有问题:def get_queryset(self):    """    :return: filtered queryset based on request query_param    """    # todo#amedeo: improve the readability code    qs = super(ChecklistViewSet, self).get_queryset()    _pk = self.kwargs['pk']    if self.request.method == 'PUT':        instance = qs.filter(pk=int(_pk)).first()        # pass in the instance we want to update        serializer = ChecklistSerializer(instance, self.request.data)        # validate and update        if serializer.is_valid():            serializer.save()            serializer_dict = serializer.data            serializer_dict["message"] = "Checklist updated successfully."            return response.Response(serializer_dict, status=status.HTTP_200_OK)        else:            return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)在我的代码中,objetc 被保存,但响应给出了一个错误,说:AttributeError: 'Response' 对象没有属性 'model'我的序列化程序是:class ChecklistSerializer(serializers.ModelSerializer):class Meta:    model = Checklist    fields = ('id', 'approved_by', 'role', 'hardship_classification',              'total_capacity', 'capacity_for_residents', 'checklist_type',              'state', 'pdf', 'submitting_afp', 'disabled', 'location')我通过传递 json 的客户端 PUT 方法调用:{"approved_by": "Test","role": "test_role_4","hardship_classification": "test_6","total_capacity": "50","capacity_for_residents": "350","checklist_type": "permanent","state": "qcl_draft","pdf": null,"submitting_afp": 3999,"disabled": false,"location": 97}
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 261 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号