Django change password

Trying to change password using PasswordChangeView, but cannot get it working.

urls.py

from django.contrib.auth import views as auth_views

urlpatterns = [
    path('profiles/settings/', update_profile, name='update_profile'),
    path('profiles/settings/', auth_views.PasswordChangeView.as_view(template_name='accounts/settings.html'), 
        name='password_change'),
]

And i am trying to get the input fields correct in my html

            <div class="tab-pane fade" role="tabpanel" id="password">
                <form id="id_password_change_form" method="POST" class="form-signin">{% csrf_token %}
                  <div class="form-group row align-items-center">
                    <label class="col-3">Current Password</label>
                    <div class="col">
                      <input 
                      type="password" 
                      placeholder="Enter your current password" 
                      name="old_password" 
                      class="form-control" 
                      id="id_old_password" 
                      required="true" />
                    </div>
                  </div>
                  <div class="form-group row align-items-center">
                    <label class="col-3">New Password</label>
                    <div class="col">
                      <input 
                      type="password" 
                      placeholder="Enter a new password" 
                      name="new_password1" 
                      class="form-control" 
                      id="id_new_password1" 
                      required="true" />
                      <small>Password must be at least 8 characters long</small>
                    </div>
                  </div>
                  <div class="form-group row align-items-center">
                    <label class="col-3">Confirm Password</label>
                    <div class="col">
                      <input 
                      type="password" 
                      placeholder="Confirm your new password" 
                      name="new_password2" 
                      class="form-control" 
                      id="id_new_password2" 
                      required="true" />
                    </div>
                  </div>
                  {% for field in form %}
                    {% for error in field.errors %}
                      <p style="color: red">{{ error }}</p>
                    {% endfor %}
                  {% endfor %}
                  <div class="d-flex justify-content-end">
                    <button type="submit" class="btn btn-primary">Change Password</button>
                  </div>
                </form>

There is no error, and it do not update the password as supposed to. according to PasswordChangeView, I should not need to alter anything.


Solution 1:

I think you have a problem because of the wrong URLs definition, take a look at you urls.py:

from django.contrib.auth import views as auth_views

urlpatterns = [
    path('profiles/settings/', update_profile, name='update_profile'),
    path('profiles/settings/', auth_views.PasswordChangeView.as_view(template_name='accounts/settings.html'), 
        name='password_change'),
]

You always hit update_profile view instead of PasswordChangeView. I think this is typo.