Tôi đang cố gắng hiển thị một ModelForm đơn giản cho tiểu sử của người dùng và cho phép người dùng cập nhật hồ sơ. Vấn đề ở đây là logic của tôi là bằng cách nào đó thiếu sót, và sau khi một cuộc gọi form.save() thành công, các giá trị cũ hiển thị trên trang. Nó không phải là cho đến khi làm mới mà giá trị thích hợp được hiển thị. Có gì sai ở đây?Django, cập nhật hồ sơ người dùng với ModelForm
@login_required
def user_profile(request):
success = False
user = User.objects.get(pk=request.user.id)
upform = UserProfileForm(instance=user.get_profile())
if request.method == 'POST':
userprofile = UserProfileForm(request.POST, instance=user.get_profile())
if userprofile.is_valid():
up = userprofile.save(commit=False)
up.user = request.user
up.save()
success = True
return render_to_response('profile/index.html',
locals(), context_instance=RequestContext(request))
Tôi chỉ đang tìm cách cập nhật tiểu sử hiện có, không thêm tiểu sử mới.