满口金牙
2022-06-10 23:02
采纳率: 90.9%
浏览 31
已结题

django for i in request.data 循环获取参数请教


    def patch(self, request):
        try:
            gr_member = WorkGroupMember.objects.get(username=request.user.username,id_group = request.user.gr_list[0])
            # 在不确定前端传过来的值时,循环获取,
            for param in request.data:
                print('param', param)
                gr_member[param] = request.data.get(param)
           # 写死是这样gr_member.xx    现在 xx要换成变量,不知道咋弄了
           # gr_member[param] 这里这样写不行,会报错,有什么好办法处理?
            gr_member.save()
            return Response()
        except Exception as e:
            print('错在哪',e)
            return Response(status=status.HTTP_400_BAD_REQUEST)

2条回答 默认 最新

相关推荐 更多相似问题