, 'django.contrib.auth.views.passwor...">

How to use inline view 'password_reset' in Django?

I set the following entry in urls.py

(r'^password_reset/$', 'django.contrib.auth.views.password_reset'), 

but as soon as I go to http://127.0.0.1:8000/password_reset/ , I get an error message:

 NoReverseMatch at /password_reset/ Reverse for 'django.contrib.auth.views.password_reset_done' with arguments '()' and keyword arguments '{}' not found. 

I expected that the password_reset_done view would also be released out of the box. So what should I do at this point?

UPDATE

After trying to solve Blair, I took a step closer.

 (r'^password_reset_done/$', 'django.contrib.auth.views.password_reset_done'), 

According to the book โ€œDeveloping a Django 1.0 Site,โ€ these inline views should be used out of the box without too much hassle. But maybe that has changed from Django 1.0 ... It would be great if someone could shed some light on this. Thanks

+7
source share
3 answers

I finally found a solution. I think there is always a slight misunderstanding between MVC and MTV. In MTV (Django), a view denotes a controller, and a template is a view.

Therefore, although it is true that the password for changing the "View" comes from the built-in pre-built template, the actual templates (appearance and style) should still be generated by the user, while the basic form (widget) is automatically created by Django. This becomes clearer when viewing the code.

So add these two lines to url.py

 (r'^change-password/$', 'django.contrib.auth.views.password_change'), (r'^password-changed/$', 'django.contrib.auth.views.password_change_done'), 

Then in the myproject / templates / registration section add these two files

password_change_done.html

 {% extends "base.html" %} {% block title %}Password Change Successful{% endblock %} {% block head %}Password Change Completed Successfully{% endblock %} {% block content %} Your password has been changed successfully. Please re-login with your new credentials <a href="/login/">login</a> or go back to the <a href="/">main page</a>. {% endblock %} 

password_change_form.html

 {% extends "base.html" %} {% block title %}Change Registration{% endblock %} {% block head %}Change Registration{% endblock %} {% block content %} <form method="post" action="."> {{form.as_p}} <input type="submit" value="Change" /> {% csrf_token %} </form> {% endblock %} 

enter image description here

+3
source

Django needs to know which URL redirects the user as soon as they fill out the form on the password_reset page. So add another line to your URL configuration:

 (r'^password_reset_done/$', 'django.contrib.auth.views.password_reset_done'), 
+2
source

As of django 1.11 password_change view is deprecated.

Deprecated since version 1.11: a view based on the password_change function should be replaced with the PasswordChangeView class.

What worked for me:

In urls.py

 from django.contrib.auth import views as auth_views ... url('^account/change-password/$', auth_views.PasswordChangeView.as_view( template_name='registration/passwd_change_form.html'), name='password_change'), url(r'^account/password-change-done/$', auth_views.PasswordChangeDoneView.as_view( template_name='registration/passwd_change_done.html'), name='password_change_done'), 

Then add a couple of passwd_change_form.html and passwd_change_done.html templates in the registration section.

Please note that I do not use the default name, for some reason, when I did this by default for django admin views.

0
source

All Articles