Reset link is missing even if I include "django.contrib.auth.urls"


this is native django 4.2 code:



<form action="{{ app_path }}" method="post" id="login-form">{% csrf_token %}


  {% url 'admin_password_reset' as password_reset_url %}

  {% if password_reset_url %}

  <div class="password-reset-link">

    <a href="{{ password_reset_url }}">{% translate 'Forgotten your password or username?' %}</a>


  {% endif %}





urlpatterns = [


    path("password_reset/", views.PasswordResetView.as_view(), name="password_reset"),



In template is expected admin_password_reset but auth module generates password_reset!

This is my project

urlpatterns = []

if settings.DEBUG:
    urlpatterns += [
        path('__debug__/', include(debug_toolbar.urls)),
        *static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT),

urlpatterns += [
    # API
    path('api/ ', include('')),

    # extra pages
    path('changelog/', management_views.changelog, name='changelog'),

    # (due to password reset)
    path('accounts/', include('django.contrib.auth.urls')),
    path('accounts/password_reset/', PasswordResetView.as_view(), name='admin_password_reset'),

    # modules
    path('authentication/', include('apps.authentication.urls')),
    path('management/', include('')),

    # native admin URLs
    path('',,  # must be last if admin URL is empty!

Notice that I had to add the extra

path('accounts/password_reset/', PasswordResetView.as_view(), name='admin_password_reset'),

with the requiring name admin_password_reset to display the reset password link.
Another solution would be to override the admin/login.html and admin_password_reset change to password_reset:

{% url 'password_reset' as password_reset_url %}

It obviously looks as bug and when I search stackoverflow topics and other, this bug is contained in django very long time…

My expectation is just to add

    path('accounts/', include('django.contrib.auth.urls')),

to and the reset link should be displayed without other extra changes. Or am I wrong? :slightly_smiling_face:


You’ve properly identified the situation.

However, this is not a bug. It is the documented behavior.

See Adding a password reset feature

Thanks for the link to the documentation. I know that the reset link and the page is not allowed by default and that’s expected.
There is described the adding link by adding this to

path('accounts/password_reset/', PasswordResetView.as_view(), name='admin_password_reset')

However I still don’t get why adding this there doesn’t make the reset link to display…

path('accounts/', include('django.contrib.auth.urls'))

What’s the main reason not to have this in the login template?

  {% url 'password_reset' as password_reset_url %}

The behavior wouldn’t be changed - reset link still wouldn’t be displayed by default… :slight_smile: