django后端直接更新数据库, 像实体类一样直接更新

2021-06-17 19:57:49 浏览数 (1)

代码语言:javascript复制
def updatexxxs(request):
    """更新信息"""
    systemDict = {}
    for key in request.POST:
        systemDict[key] = request.POST.get(key)
    print(systemDict)
    try:
        Employee.objects.filter(username=systemDict['username']).update(**systemDict)
        data = {
            "code": 200,
            "msg": '更新成功'
        }
        resp = JsonResponse(data)
        return resp
    except:
        data = {
            "code": 400,
            "msg": '更新失败'
        }
        resp = JsonResponse(data)
        return resp

0 人点赞