I am trying to create a system for resetting forgotten passwords through email but am getting some errors.
My urls are:
from django.contrib.auth import views as auth_views
urlpatterns = [
url(r'^$', auth_views.login, name='login'),
url(r'^logout/$', auth_views.logout, name='logout'),
## more irrelevant urls here ##
url(r'^password/reset/done/$', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
url(r'^password/reset/$', auth_views.PasswordResetView.as_view(), name='password_reset'),
url(r'^password/reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
url(r'^password/reset/complete/$', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]
When the email address is submitted at password_reset
, the email sends but I get this error:
Internal Server Error: /password/reset/
Traceback (most recent call last):
File "C:\python\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
response = get_response(request)
File "C:\python\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\python\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\python\lib\site-packages\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "C:\python\lib\site-packages\django\utils\decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "C:\python\lib\site-packages\django\utils\decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\python\lib\site-packages\django\utils\decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "C:\python\lib\site-packages\django\contrib\auth\views.py", line 439, in dispatch
return super(PasswordResetView, self).dispatch(*args, **kwargs)
File "C:\python\lib\site-packages\django\views\generic\base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "C:\python\lib\site-packages\django\views\generic\edit.py", line 183, in post
return self.form_valid(form)
File "C:\python\lib\site-packages\django\contrib\auth\views.py", line 453, in form_valid
return super(PasswordResetView, self).form_valid(form)
File "C:\python\lib\site-packages\django\views\generic\edit.py", line 79, in form_valid
return HttpResponseRedirect(self.get_success_url())
File "C:\python\lib\site-packages\django\views\generic\edit.py", line 67, in get_success_url
if self.success_url:
File "C:\python\lib\site-packages\django\utils\functional.py", line 114, in __wrapper__
res = func(*self.__args, **self.__kw)
File "C:\python\lib\site-packages\django\urls\base.py", line 91, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "C:\python\lib\site-packages\django\urls\resolvers.py", line 497, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name.
[11/Feb/2018 14:32:04] "POST /password/reset/ HTTP/1.1" 500 121086
When I copy the link into the browser and reset the password, the password resets correctly but the following error appears:
Internal Server Error: /password/reset/MQ/set-password/
Traceback (most recent call last):
File "C:\python\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
response = get_response(request)
File "C:\python\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\python\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\python\lib\site-packages\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "C:\python\lib\site-packages\django\utils\decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "C:\python\lib\site-packages\django\views\decorators\debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "C:\python\lib\site-packages\django\utils\decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "C:\python\lib\site-packages\django\utils\decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "C:\python\lib\site-packages\django\views\decorators\cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\python\lib\site-packages\django\utils\decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "C:\python\lib\site-packages\django\contrib\auth\views.py", line 489, in dispatch
return super(PasswordResetConfirmView, self).dispatch(*args, **kwargs)
File "C:\python\lib\site-packages\django\views\generic\base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "C:\python\lib\site-packages\django\views\generic\edit.py", line 183, in post
return self.form_valid(form)
File "C:\python\lib\site-packages\django\contrib\auth\views.py", line 522, in form_valid
return super(PasswordResetConfirmView, self).form_valid(form)
File "C:\python\lib\site-packages\django\views\generic\edit.py", line 79, in form_valid
return HttpResponseRedirect(self.get_success_url())
File "C:\python\lib\site-packages\django\views\generic\edit.py", line 67, in get_success_url
if self.success_url:
File "C:\python\lib\site-packages\django\utils\functional.py", line 114, in __wrapper__
res = func(*self.__args, **self.__kw)
File "C:\python\lib\site-packages\django\urls\base.py", line 91, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "C:\python\lib\site-packages\django\urls\resolvers.py", line 497, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'password_reset_complete' not found. 'password_reset_complete' is not a valid view function or pattern name.
[11/Feb/2018 14:37:16] "POST /password/reset/MQ/set-password/ HTTP/1.1" 500 134868
Technically the system functions, but obviously these error messages are not ideal.
These are the other questions I have asked about this:
NoReverseMatch error with password reset emails
Error with system for email password resets
And this is the tutorial I followed.