django password change form not working.Am only getting 'old password is entered incorrectly'

时间:2018-09-22 23:01:11

标签: django python-3.x

from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth import update_session_auth_hash
from django.contrib import messages 

def change_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request, 'Your password was successfully updated!')
            return redirect('change_password')
        else:
            messages.error(request, 'Please correct the error below.')
    else:
        form = PasswordChangeForm(request.user)
    return render(request, 'accounts/change_password.html', {
        'form': form
    })

I am not able to change my old password, because I am getting incorrect old password error, but I can still login with that same old password. But when when i try to change it, it seems to be incorrect.

0 个答案:

没有答案