Opened 4 years ago
Last modified 4 years ago
#32349 closed Bug
unable to obtain auth template password_reset_done when using namespaced urls — at Version 1
Reported by: | James Miller | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 3.1 |
Severity: | Normal | Keywords: | password_reset |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hi,
Whilst setting up a users app, I found that if I namespaced my urls, ie :
<django_users_app/urls.py> app_name = 'django_users_app' urlpatterns = [ path('accounts/', include('django.contrib.auth.urls')), path('login/', UserLoginView.as_view(), name='login'), path('dashboard/', DashboardView.as_view(), name='dashboard'), path('register/', RegisterView.as_view(), name='register'), path('profile/', ProfileView.as_view(), name='profile') ]
Then when I completed a password reset accessed from a link on the login page, the server crapped out and informed me that:
Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name.
All my other password reset views work though.
I discovered that in django.contrib.auth.views the class PasswordResetView(PasswordContextMixin, FormView): has a success_url of:
reverse_lazy('password_reset_done')
When I edit the code and replace the above with reverse_lazy('django_users_app:password_reset_done') the correct template is returned.
If I do not edit the code, but instead remove the namespace and its reference in all my files, then the correct template is returned.
I want to know if it is possible to use a namespace with a users app that references the contrib.auth password reset templates.
There is conflicting information on the internet regarding this issue and no clear indication that I can see in the django docs.
Also, in my settings file, I have the following setting defined:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
Yet when I use reset the password, I do not see any email sent. I don't know if this is a related error.
Below is the traceback information from the page when password_reset_done cannot be found:
Environment: Request Method: POST Request URL: http://127.0.0.1:8000/users/accounts/password_reset/?next=/users/login/ Django Version: 3.1.5 Python Version: 3.9.1 Installed Applications: ['django_users_app', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_email_verification', 'captcha'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in _wrapper return bound_method(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/views.py", line 222, in dispatch return super().dispatch(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch return handler(request, *args, **kwargs) File "/usr/local/lib/python3.9/site-packages/django/views/generic/edit.py", line 142, in post return self.form_valid(form) File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/views.py", line 236, in form_valid return super().form_valid(form) File "/usr/local/lib/python3.9/site-packages/django/views/generic/edit.py", line 57, in form_valid return HttpResponseRedirect(self.get_success_url()) File "/usr/local/lib/python3.9/site-packages/django/views/generic/edit.py", line 51, in get_success_url if not self.success_url: File "/usr/local/lib/python3.9/site-packages/django/utils/functional.py", line 135, in __wrapper__ res = func(*self.__args, **self.__kw) File "/usr/local/lib/python3.9/site-packages/django/urls/base.py", line 87, in reverse return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) File "/usr/local/lib/python3.9/site-packages/django/urls/resolvers.py", line 685, in _reverse_with_prefix raise NoReverseMatch(msg) Exception Type: NoReverseMatch at /users/accounts/password_reset/ Exception Value: Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name.