Reverse for 'password_reset_confirm' not found.

So I’m trying to use the default reset password form from django and this is my urls now:

urls:

    path('reset_password/',
        auth_views.PasswordResetView.as_view(success_url=reverse_lazy('home:password_reset_done'), template_name="accounts/password_reset.html"),
        name="reset_password"),

    path('reset_password_sent/', 
        auth_views.PasswordResetDoneView.as_view(template_name="accounts/password_reset_sent.html"), 
        name="password_reset_done"),

    path('reset/confirm/<uidb64>/<token>/',
        auth_views.PasswordResetConfirmView.as_view(success_url=reverse_lazy('home:password_reset_complete'), template_name="accounts/password_reset_form.html"), 
        name="password_reset_confirm"),

    path('reset_password_complete/', 
        auth_views.PasswordResetCompleteView.as_view(template_name="accounts/password_reset_done.html"), 
        name="password_reset_complete"),
]

I did the success url thing because my stuff is in the home folder so django can find where the stuff is and the first view is rendered but after I click the reset button this error appears:

Internal Server Error: /reset_password/
Traceback (most recent call last):
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\views.py", line 222, in dispatch
    return super().dispatch(*args, **kwargs)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\generic\edit.py", line 142, in post
    return self.form_valid(form)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\views.py", line 235, in form_valid
    form.save(**opts)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\forms.py", line 310, in save
    self.send_mail(
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\forms.py", line 253, in send_mail
    body = loader.render_to_string(email_template_name, context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 170, in render
    return self._render(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 162, in _render
    return self.nodelist.render(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 938, in render
    bit = node.render_annotated(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\defaulttags.py", line 39, in render
    output = self.nodelist.render(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 938, in render
    bit = node.render_annotated(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\loader_tags.py", line 53, in render
    result = self.nodelist.render(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 938, in render
    bit = node.render_annotated(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\defaulttags.py", line 446, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\base.py", line 86, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\urls\resolvers.py", line 694, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.

I cant find the error, at my opnion the view is correct.

Please help :slight_smile:

I think we’re going to need to see everything that you’ve customized here. Are those custom templates being used? Please post them. Are those custom views? Please post them. (For both of these, it would be the initial view / template where you say “I click the reset button”, and the view & template for where that first view directs you after the button click.) Do you have an apps.py file defining a “home” app? Please post it.

so this is my whole urls the apps_name is on the top

from django.contrib.auth.forms import PasswordChangeForm
from django.urls import path
from django.contrib.auth import views as auth_views
from django.urls.base import reverse_lazy

from . import views
app_name = 'home'
urlpatterns = [
    path('', views.index_view, name="index"),
    path('login/', views.login_view, name="login"),
    path('register/', views.register_view, name="register"),
    path('logout/', views.logout_view, name="logout"),
    path('profile/', views.profile_view, name="profile"),
    path('settings/', views.profilesettings_view, name="profilesettings"),
    path('settings/prename/', views.AccountInfoPrename, name="ps_prename"),
    path('settings/surname/', views.AccountInfoSurname, name="ps_surname"),
    path('settings/company/', views.AccountInfoCompany, name="ps_company"),
    path('settings/country/', views.AccountInfoCountry, name="ps_country"),
    path('settings/email/', views.email_settings_view, name="emailsettings"),
    path('settings/language/', views.language_settings_view, name="languagesettings"),
    path('plans/', views.plans_view, name="plans"),
    path('settings/password/', views.PasswordChangeView.as_view(success_url=reverse_lazy('home:password_success'), template_name='home/password_settings.html'), name="passwordsettings"),
    path('settings/password_success/', views.password_success, name="password_success"),


    path('reset_password/',
        auth_views.PasswordResetView.as_view(success_url=reverse_lazy('home:password_reset_done'), template_name="accounts/password_reset.html"),
        name="reset_password"),

    path('reset_password_sent/', 
        auth_views.PasswordResetDoneView.as_view(template_name="accounts/password_reset_sent.html"), 
        name="password_reset_done"),

    path('reset/confirm/<uidb64>/<token>/',
        auth_views.PasswordResetConfirmView.as_view(success_url=reverse_lazy('home:password_reset_complete'), template_name="accounts/password_reset_form.html"), 
        name="password_reset_confirm"),

    path('reset_password_complete/', 
        auth_views.PasswordResetCompleteView.as_view(template_name="accounts/password_reset_done.html"), 
        name="password_reset_complete"),
]

the rest are just normal html forms with some text and the form in the passwort_reset.html

<h3>Password reset</h3>

<p>Forgotten your password? Enter your email address below, and we’ll email instructions for setting a new one.</p>

<form method="post">

	{% csrf_token %}
	{{form}}
	<input type="Submit" name="Send email">
	
</form>

Ok, that’s the first one. Clicking on the button is going to direct you to (if I’m reading it correctly) ‘reset_password_sent/’, which is going to render “accounts/password_reset_sent.html” - we need to see that too, since the error message appears to be in the location where a template is being rendered.

there is just some text inside


<h3>Password reset sent</h3>


<p>We’ve emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly.</p>

<p>If you don’t receive an email, please make sure you’ve entered the address you registered with, and check your spam folder.</p>

do I need an extra view for that which isnt in urls? Because I havent an etxra view for that

Are these both the complete templates involved? Or is there more that has been edited out?

nope they are complete

but maybe thats the problem, what else do I need in the template

One issue is that the urls you’ve posted is within an app with the app_name property set to "home". This means the full url name is home:password_reset_confirm as per the docs here. You need to either change the references to that URL or elevate the password reset urls to the root definition of your urls.

I’d opt for the latter half, because the former may need you to redefine templates/code only to use the correct url name. The latter avoids that by keeping it as password_reset_confirm.

Let me know if I can improve on my explanation.

worked, thanks for your help

I have the same problem. What changes you did?

Chnaged the reference to the URL including my app_name → “home”, as Tim said

But its 7 months ago I cant explain it in detail because I dont know what I did back then.

1 Like