title: Allow user to edit profile information and submit it causing page to redirect to profile page.
body: <p>In django I am attempting to allow that user to edit his/her profile information, press submit, and have the the change reflect in his/her profile page. </p>
  
  <p>This is the code : </p>
  
  <p>In the views.py document in my application </p>
  
  <blockquote>
    <p>User is allowed to view the profile page</p>
  </blockquote>
  
  <pre><code>def view_profile(request):
  
      var = { 'user' : request.user }
  
      return render(request, 'accounts/profile.html', var)
  </code></pre>
  
  <blockquote>
    <p>User is allowed to edit the profile page</p>
  </blockquote>
  
  <pre><code>def edit_profile(request):
  
      if request.method == 'POST':
          form = UserChangeForm(request.POST, instance=request.user)
  
          if form.is_valid():
              form.save()
  
              return redirect('account/profile')
  
      else:
  
          form = UserChangeForm(instance=request.user)
  
          var = {'form' : form }
          return render(request, 'accounts/edit_profile.html', var)
  </code></pre>
  
  <p>This is the urls.py document </p>
  
  <blockquote>
    <p>Import modules</p>
  </blockquote>
  
  <pre><code>from django.conf.urls import url
  from . import views
  </code></pre>
  
  <blockquote>
    <p>Defined the urls</p>
  </blockquote>
  
  <pre><code>urlpatterns = [
  
  url(r'^profile/$', views.view_profile, name = 'view_profile'),  
  url(r'^profile/edit/$', views.edit_profile, name = 'edit_profile')
  
  ]
  </code></pre>
  
  <p>This is the edit_profile </p>
  
  <pre><code>{% extends 'base.html' %}
  
  
  {%  block head %}
  
  &lt;title&gt;{{ user }}&lt;/title&gt;
  
  {% endblock %}
  
  
  {%  block body %}
  
  &lt;div class = "container"&gt;
  
  &lt;form method = "post"&gt;
  
      {% csrf_token %}
  
      {{ form.as_p }}
  
      &lt;button class = "btn btn-default" type="submit"&gt;Submit&lt;/button&gt;
  
  &lt;/form&gt;
  
  &lt;/div&gt;
  
  {% endblock %}
  </code></pre>
  
  <p>When I edit user model on the <code>edit_profile.html</code> page and submit, it redirects </p>
  
  <p>from : </p>
  
  <p><a href="http://127.0.0.1:8000/account/profile/edit/" rel="nofollow noreferrer">http://127.0.0.1:8000/account/profile/edit/</a></p>
  
  <p>To : </p>
  
  <p><a href="http://127.0.0.1:8000/account/profile/edit/account/profile" rel="nofollow noreferrer">http://127.0.0.1:8000/account/profile/edit/account/profile</a></p>
  
  <p>This latter urls is not accurate, it should redirect </p>
  
  <p>To : </p>
  
  <p><a href="http://127.0.0.1:8000/account/profile" rel="nofollow noreferrer">http://127.0.0.1:8000/account/profile</a></p>
  
  <p>This is how that page looks </p>
  
  <p><a href="https://i.stack.imgur.com/b5tFb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b5tFb.png" alt="enter image description here"></a></p>