Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
def passchange(request):
    if request.user.is_authenticated:
        if request.method == "POST":
            print(request.POST)
            fm = PasswordChangeForm(user=request.user, data=request.POST)
            print(fm)
            if fm.is_valid():
                fm.save()
                update_session_auth_hash(request, fm.user)
                messages.success(request, 'Password Changed Successfully')
                if fm.user.location=="Latur":
                    return HttpResponseRedirect('/laturhome/')
                elif fm.user.location=="Nashik":
                    return HttpResponseRedirect('/nashikhome/')
                elif fm.user.location=="Dhule":
                    return HttpResponseRedirect('/dhulehome/')
                elif fm.user.location=="Akola":
                    return HttpResponseRedirect('/akolahome/')
                elif fm.user.location=="Solapur":
                    return HttpResponseRedirect('/solapurhome/')
            else:
                print(fm.error_messages)
                return HttpResponse('Not valid')
        else:
            fm = PasswordChangeForm(user=request.user)
            return render(request, 'account/passchange.html', {'form':fm})
    else:
        return HttpResponseRedirect('/login/')


What I have tried:

I had to create a custom user model using AbstractBaseUser as I needed some more fields in my registration form. But since then, all my view functions which involve is_valid method, failed to validate the entered data and I had to validate them manually. Similarly, When I'm up to creating a password change form using PasswordChangeForm, the validation fails and gives me ValueError returning None. Only this time I'm struggling to figure out how to validate the entered data without using is_valid() method. Is there a way?
Posted
Updated 17-Jun-21 0:37am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900