Password change and reset views, url NoReverseMatch

i’ve configured a seperate app to manage logins,logout, password change and reset…However after changing password at :
name= password_change after password has been change it supposed to return page urlpattern name = password_change_done but it keeps returning an error saying :

NoReverseMatch at /accounts/password-change

Reverse for ‘password_change_done’ not found. ‘password_change_done’ is not a valid view function or pattern name.

app_name = 'accounts'

    path('password-reset',views.PasswordReset.as_view(), name="password_reset"),
    path('password-reset/done',views.PasswordResetDone.as_view(), name="password_reset_done"),
    path('password-reset/confirm',views.PasswordResetConfirm.as_view(), name="password_reset_confirm"),
    path('password-reset/complete',views.PasswordResetComplete.as_view(), name="password_reset_complete"),

By using the app_name attribute, you have created a namespace for those urls, which needs to be specified when referencing those urls by name.

See the docs and examples at URL dispatcher | Django documentation | Django

Fixed the issue my registering no namespace nor app_name… However the page password_reset_complete keeps returning this error : suggesting the namepace = accounts isn’t registered but i don’t have it anywhere registered in the app.

Internal Server Error: /accounts/password-reset/complete
Traceback (most recent call last):
  File "c:\Users\USER\Desktop\DB\prohub\.venv\lib\site-packages\django\urls\", line 71, in reverse
    extra, resolver = resolver.namespace_dict[ns]
KeyError: 'accounts'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\USER\Desktop\DB\prohub\.venv\lib\site-packages\django\core\handlers\", line 55, in inner
    response = get_response(request)
  File "c:\Users\USER\Desktop\DB\prohub\.venv\lib\site-packages\django\core\handlers\", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "c:\Users\USER\Desktop\DB\prohub\.venv\lib\site-packages\django\views\generic\", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "c:\Users\USER\Desktop\DB\prohub\.venv\lib\site-packages\django\views\generic\", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "c:\Users\USER\Desktop\DB\prohub\.venv\lib\site-packages\django\views\generic\", line 226, in get
    context = self.get_context_data(**kwargs)
  File "c:\Users\USER\Desktop\DB\prohub\.venv\lib\site-packages\django\contrib\auth\", line 344, in get_context_data
    context["login_url"] = resolve_url(settings.LOGIN_URL)
  File "c:\Users\USER\Desktop\DB\prohub\.venv\lib\site-packages\django\", line 180, in resolve_url
    return reverse(to, args=args, kwargs=kwargs)
  File "c:\Users\USER\Desktop\DB\prohub\.venv\lib\site-packages\django\urls\", line 82, in reverse
    raise NoReverseMatch("%s is not a registered namespace" % key)
django.urls.exceptions.NoReverseMatch: 'accounts' is not a registered namespace
[09/Jul/2024 18:00:06] "GET /accounts/password-reset/complete HTTP/1.1" 500 96573

Are you using a system-provided template or a template that you have created for the view being called by the /accounts/password-reset/complete url?

Please post your PasswordResetComplete view and the template it is rendering. :

import django.contrib.auth.views as auth_views

class PasswordResetComplete(auth_views.PasswordResetCompleteView):
    template_name = 'registration/password-reset/password-reset-complete.html'

template :

<title>Password reset complete</title>
    <h3>Password set</h3>
    <p>Your new password has been set <a href="{%url 'user_login' %}">login</a></p>

What is your LOGIN_URL setting?

Forgotten i had the namespace accounts registered to the LOGIN_URL and LOGOUT_URL pattern name.

The issue has been rectified now…Thanks alot Man :slight_smile: