문제

My problem is: when I submit the form it falls into the else: block below that I have defined in my view.

What I'm trying to accomplish: allow a user to reset their password using the django 1.5 built in PasswordResetForm functionality in django auth

Views.py

def UserResetPassword(request):
    form = UserForgotPasswordForm(None, request.POST)
    if request.method == 'POST':
        if form.is_valid():
            form.save(from_email='admin@thedomain.com',email_template_name='mysite/reuse/forgotpassword.html', use_https=False,token_generator=default_token_generator, html_email_template_name=None)
        else:
            return HttpResponse("Are you sure you entered that correctly?")

    return render(request, 'mysite/reuse/forgotpassword.html', {
        'form':form
    })

Upon submitting the form it outputs: Are you sure you entered that correctly? (e.g. the value being sent from the else: condition

What am I doing wrong here?

도움이 되었습니까?

해결책

I see a couple of issues:

def UserResetPassword(request):
    form = UserForgotPasswordForm(request.POST or None) #data=is request.POST or None
    if request.method == 'POST':
        if form.is_valid():
            form.save(from_email = 'admin@thedomain.com', email_template_name= 'mysite/reuse/forgotpassword.html', use_https = False, token_generator = default_token_generator, html_email_template_name=None)

    return render(request, 'mysite/reuse/forgotpassword.html', {
        'form':form
    })

Also, get rid of the else part. You want to be able to see what the error is. render() would show the errors.

In the forms,

fields = ("email")

should be

fields = ("email", )

Also, you should be using PasswordChangeForm if you want a form that lets a user change his/her password by entering their old password.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top