Click here to Skip to main content
15,671,201 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":
            fm = PasswordChangeForm(user=request.user, data=request.POST)
            if fm.is_valid():
                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/')
                return HttpResponse('Not valid')
            fm = PasswordChangeForm(user=request.user)
            return render(request, 'account/passchange.html', {'form':fm})
        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?
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