Saturday, June 10, 2017

Re: url and view for updating django userprofile

Here is the problem line in your view:

return redirect('success:profile_accounts')

You'll need to create an appropriate URL entry for your form submission redirect.

-James

On Jun 10, 2017 9:23 AM, "change i need" <ngabe1990@gmail.com> wrote:
 Here is my model.py 


# User profile model
class UserProfile(models.Model):
user = models.OneToOneField(User,unique=True,on_delete=models.CASCADE)
bio = models.TextField(max_length=500,null=True,blank=True)
picture = models.ImageField(upload_to="profile_image",null=True,blank=True,)
company = models.TextField(max_length=500,null=True)



html file


<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %} {{ user_form.as_p }} {{ profile_form.as_p }} <button type="submit">Save changes</button>

</form>


My view.py


def update_profile(request):
if request.method == 'POST':
create_account_form = Creat_account(request.POST,instance=request.user)
profile_form = ProfileForm(request.POST,instance=request.user.userprofile)
if create_account_form.is_valid() and profile_form.is_valid():
create_account_form.save()
profile_form.save()
messages.success(request,'Your Profile has been Updated')
return redirect('success:profile_accounts')
else:
messages.error(request,'fill out the fields correctly')
else:
create_account_form =Creat_account(instance = request.user)
profile_form = ProfileForm(instance=request.user.userprofile)
return render(request,"success/user_account/edit_profile.html",{'user_form':create_account_form,'profile_form':profile_form})
url.py

url(r'Update_profil/$',views.update_profile,name="Profile_update"),
error when form summited

Reverse for 'profile_accounts' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/81c9f0a7-e2ca-47e1-b7db-826e6610cccc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUvYjuXhXiv52-_%3D-1ZQ3zGnNFOV1G452VBHMsJGdeWYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment