0
votes

I am implementing reset page for my django application. Everything works fine if i use auth_views.PasswordResetView.as_view() without passing in template_name. It uses default django provided templates and i get confirmation email and password is successfully reset but i want to pass in my own template to do so which has simple form with an image and one input tag for email. The view shows up fine but when i click submit it only shows 1 post request in console.

I have tried implementing registration directory since in source code it uses that but no luck so far. I have also changed input to a button for submitting. I tried removing extra styling classes for css too.

I am using following path for reset page.

path('login/password-reset/',
        auth_views.PasswordResetView.as_view(),
        name = 'password_reset' ),

Passing following generated the view but when i submit the email it doesnt get me to reset_done.

 path('login/password-reset/',
        auth_views.PasswordResetView.as_view(template_name = 'login/password_reset_form.html'),
        name = 'password_reset' ),

Rest of my urls are as follows:

path('login/password-reset/done',
        auth_views.PasswordResetDoneView.as_view(),
        name = 'password_reset_done' ),   
path('login/password-reset-confirm/<uidb64>/<token>/',
        auth_views.PasswordResetConfirmView.as_view(),
        name = 'password_reset_confirm' ),      
path('login/password-reset-complete/',
        auth_views.PasswordResetCompleteView.as_view(),
         name='password_reset_complete'),    

template is here:

<form method="POST" class="register-form" id="login-form" action= '' >
{% csrf_token %}
<div class="form-group">
    <label for="your_name">Enter registered email</label>
    <input type="text" name="your_name" id="your_name" placeholder="Email"/>
</div>
<div class="form-group">
    <input type="submit" name="signin" id="signin" class="form-submit" value="Reset"/>
</div>
</form>

Any help would be appreciated!

1
Presumably the issue is with your template - please post the contents of the template file.solarissmoke
I have updated my question with the template link. Sorry totally forgot to attach it earlier.sh_07

1 Answers

2
votes

Your custom template has this input:

<input type="text" name="your_name" id="your_name" placeholder="Email"/>

Which is invalid because Django's PasswordResetForm expects a field whose name is email, not your_name. Thus the form will fail to validate and the view will re-render the form with errors. You need to use something like:

<input type="text" name="email" id="id_email" placeholder="Email"/>

Even better is not to render the field yourself, but to let Django render it with:

{{ form.email.errors }}
{{ form.email }}

... so that you are not hard-coding field names. In addition you were not rendering form errors, which is why you didn't realise the form was invalid.