Resetting password changed in 1.0, and the documentation for this is missing. The basic way of using new views is to add this set to urlconf:
[rk:syntax lang="python"]
import django.contrib.auth.views
....
(r'^password_reset/$', 'django.contrib.auth.views.password_reset'),
(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
(r'^reset/(?P[0-9A-Za-z]+)-(?P.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),[/rk:syntax]
Default templates are in django/contrib/admin/templates/registration and can be used out of the box, but they have Admin Panel like look. You can set paths to your custom templates (copy & edit the original ones):
[rk:syntax lang="python"](r'^password_reset/$', 'django.contrib.auth.views.password_reset', {'template_name':'userpanel/password_reset_form.html', 'email_template_name':'userpanel/password_reset_email.html'}),
(r'^password_reset/done/$', 'django.contrib.auth.views.password_reset_done', {'template_name':'userpanel/password_reset_done.html'}),
(r'^reset/(?P[0-9A-Za-z]+)-(?P.+)/$', 'django.contrib.auth.views.password_reset_confirm', {'template_name':'userpanel/password_reset_confirm.html'}),
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete', {'template_name':'userpanel/password_reset_complete.html'}),
[/rk:syntax]
If you want to use those views wrapped in your own views, then you will get few NoReverseMatch: Reverse for 'yourapp.django.contrib.auth.views.password_reset_confirm' with arguments '()' and keyword arguments... exceptions. You have to pass to the views also a post_reset_redirect argument with URLs to other password reset views:
password_reset - URL for password_reset_done view
password_reset_confirm - URL for password_reset_complete view
password_reset_email.html - You have add in some way URL to password_reset_confirm in URL tag:
[rk:syntax lang="html"]{% url django.contrib.auth.views.password_reset_confirm uidb36=uid, token=token %}[/rk:syntax]
Example:
[rk:syntax lang="python"]def password_reset(request):
"""
django.contrib.auth.views.password_reset view (forgotten password)
"""
if not request.user.is_authenticated():
return django.contrib.auth.views.password_reset(request,
template_name='userpanel/password_reset_form.html',
email_template_name= 'userpanel/password_reset_email.html',
post_reset_redirect='/user/password_reset/done/')
else:
return HttpResponseRedirect("/user/")[/rk:syntax]
For the links in the email domain name from Sites app is used. If you change the domain in Admin Panel/Sites, then you will have to restart the server to see the changes in emails.
Comment article