django view for password_reset_confirm.html

159 views Asked by At

I am trying to implement a reset password feature in a Django Project.

I did almost everything:

  • User enters his email

  • email is sent with a link

  • User goes to the link, and type new password and confirms it

This is where I stopped.

This is the form I am using in password_reset_confirm.html:

<form action="" method="post">{% csrf_token %}
{{ form.new_password1.errors }}
<p class="aligned wide"><label for="id_new_password1">{% trans 'New password:' %}</label>{{     form.new_password1 }}</p>
{{ form.new_password2.errors }}
<p class="aligned wide"><label for="id_new_password2">{% trans 'Confirm password:' %}</label>{{     form.new_password2 }}</p>
<p><input type="submit" value="{% trans 'Change my password' %}" /></p>
</form>

Where should this form submit? what should I write in action="?"? Does Django have a view for this? or should I write one myself?

1

There are 1 answers

0
Daniel Hepper On BEST ANSWER

The action attribute should be empty so that the form is sent to the current URL.

This is the common pattern for form handling in Django: a URL displays a form on a GET request and processes it on a POST request.