Path to the templates for /accounts/login, etc.

Hi,

I am (still) a beginner in django. I am trying to use the default django user management for the user registration/login/logout/password reset functionalities.

I have added django.contrib.auth.urls to the urlpatterns, so that I could use for example http://127.0.0.1:8000/accounts/login/.

However, I am not clear on where to modify the templates for the registration/login/logout pages.

As I wasn’t able to find an answer in the documentation, I read the tutorial Django Tutorial Part 8: User authentication and permissions - Learn web development | MDN, where it mentioned that the template for the login page (accounts/login) can be stored in app/templates/registration/login.html. It works well. However, when I tried to follow the tutorial for the other templates, for example, logged_out.html, password_reset_form.html, nothing was changed and the website still uses the default django admin templates.

Could you please suggest the correct way to use the templates?

Thanks in advance!

Please be specific and show all the file names (and directories) for those templates along with any file contents created or modified for this.

Thanks for your reply!
I basically followed the tutorial, and created the following templates:
image

For example, logged_out.html simply contains the following:

{% extends "base_generic.html" %}

{% block content %}
  <p>Logged out!</p>
  <a href="{% url 'login'%}">Click here to login again.</a>
{% endblock %}

The problem is that it seems like this template is not used when I access http://127.0.0.1:8000/accounts/logout/. Still, it shows the default Django administration log out page.

I am not sure, but maybe I should add something in urls.py, to explicitly write “template_name=‘…’”, for example:

urlpatterns = [
    path(
        "change-password/",
        auth_views.PasswordChangeView.as_view(template_name="change-password.html"),
    ),
]

There isn’t anything you need to do with the urls.

Please show your TEMPLATES and INSTALLED_APPS settings in your settings.py file.

Also, is this templates directory listing you’re showing in your project directory or in an app directory?

Hi Ken,
thanks so much for your reply! Here are the settings:


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'spectrum.apps.SpectrumConfig',
]

If it’s in a project level directory, then that directory needs to be identified in the DIRS section of your TEMPLATES settings.

If it’s in an app directory, your app needs to be listed before the django apps in INSTALLED_APPS, because the template directories are searched in the order that they are listed.

Thanks so much for your help!

May I ask how to acknowledge you in a publication that might be published in several months?

The thought is appreciated but not necessary. If you like, you can acknowledge the general Django community or this forum collectively.

I see, thanks so much!