错误“由于数据未验证而无法更改”

时间:2019-06-25 03:37:28

标签: django django-views

我无法更新扩展的用户个人资料

在views.py中:

views.py

def profile(request, user_id):
user = get_object_or_404(User, id=user_id)
user_info = get_object_or_404(UserInfor, user_id=user.id)
if request.method == "POST":
    user_form = UserForm(data=request.POST or None, instance=user)
    profile_form = ProfileForm(data=request.POST or None, instance=user_info)
    user = user_form.save(commit=True)
    user_info = profile_form.save(commit=True)
    user.save()
    user_info.save()
    return render(request, 'pages/profile.html', {'user': user_form, 'user_info': profile_form, 'user_id': user_id})
else:
    user_form = UserForm(instance=user)
    profile_form = ProfileForm(instance=user_info)
    return render(request, 'pages/profile.html', {'user': user_form, 'user_info': profile_form, 'user_id': user_id})

如何解决错误?

0 个答案:

没有答案