如您所见,此函数更新用户字段,该字段取决于 GET 变量。
def update_p(request):
if request.method == "GET":
field = request.GET.get("field", "")
value = request.GET.get("value", "")
result = Users.objects.raw("SELECT id, %s FROM blog_users WHERE id = %s LIMIT 1", [field, request.session['user_id']])[0]
if result:
result = getattr(result, field)
result = value
result.save()
return HttpResponseRedirect("/blog/loggedin/profile/")
后
if result:
是我感到困惑的地方。我收到错误
AttributeError: 'unicode' object has no attribute 'save'
我不知道为什么我会收到错误,但希望它对你们所有人都是不言自明的。我怎样才能防止错误,或者有更好的方法来完成这个功能?
谢谢你的帮助。