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

Hi,

this is native django 4.2 code:

admin/login.html

...

<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>

  </div>

  {% endif %}

  ...

</form>

...

auth/urls.py:

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 urls.py:

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('apps.management.api_urls')),

    # 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('apps.management.urls')),

    # native admin URLs
    path('', admin.site.urls),  # 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 url.py and the reset link should be displayed without other extra changes. Or am I wrong? :slightly_smiling_face:

Thanks.

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 url.py:

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: