Tuesday 15 January 2013

python - Django, updating a user profile with a ModelForm -


I am trying to display a simple ModelForm for a user's profile and allow the user to update it I am The problem here is that my argument is somehow faulty, and after a successful form.save () call, the old values ​​show on the page. It is not as far as refreshing proper value is not shown. What's wrong here?

  @login_required def user_profile (requested): success = false user = user.bizjects. (Pk = request.user.id) upform = UserProfileForm (Example = User Get_profile ()) if request.method == 'POST': userprofile = UserProfileForm (request.POST, example = 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', local (), context_instance = RequestContext (request))  

I'm just looking to update an existing profile, do not add new ones.

Try this:

  @login_required def user_profile (requested): Success = false user = User.objects.get (pk = request.user.id) if request.method == 'POST': upform = UserProfileForm (request.POST, example = user.get_profile ()) if upform.is_valid ( ): Up = upform.save (commit = false) up.user = request.user up.save () success = true else: upform = UserProfileForm (example = user.get_profile ()) return render_to_response ('profile / index.html ', Local (), context_instance = RequestContext (request))  

No comments:

Post a Comment