Django Official Tutorial Part 7 - base_site.html is not overwritten (I think)

Hello Community,

I just went through the Django Tutorial and I’m stuck at the End of part 7.

Here is my file structure:

~/Projects/flglnsandbox$ tree
.
├── db.sqlite3
├── flglnsandbox
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-310.pyc
│   │   ├── settings.cpython-310.pyc
│   │   ├── urls.cpython-310.pyc
│   │   └── wsgi.cpython-310.pyc
│   ├── asgi.py
│   ├── settings.py
│   ├── templates
│   │   └── admin
│   │       └── base_site.html
│   ├── urls.py
│   └── wsgi.py
├── manage.py
└── polls
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-310.pyc
    │   ├── admin.cpython-310.pyc
    │   ├── apps.cpython-310.pyc
    │   ├── models.cpython-310.pyc
    │   ├── tests.cpython-310.pyc
    │   ├── urls.cpython-310.pyc
    │   └── views.cpython-310.pyc
    ├── admin.py
    ├── apps.py
    ├── migrations
    │   ├── 0001_initial.py
    │   ├── __init__.py
    │   └── __pycache__
    │       ├── 0001_initial.cpython-310.pyc
    │       └── __init__.cpython-310.pyc
    ├── models.py
    ├── static
    │   └── polls
    │       ├── images
    │       │   └── background.png
    │       └── style.css
    ├── templates
    │   └── polls
    │       ├── detail.html
    │       ├── index.html
    │       └── results.html
    ├── tests.py
    ├── urls.py
    └── views.py

13 directories, 35 files

Here is my settings.py:

"""
Django settings for flglnsandbox project.

Generated by 'django-admin startproject' using Django 5.0.6.

For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-1rxkt=41*h8z&lsq4jl#0e=!j-umkics*zl5ia$uz0_77-njkh'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = [
    '127.0.0.1',
]


# Application definition

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

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'flglnsandbox.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],
        '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',
            ],
        },
    },
]

WSGI_APPLICATION = 'flglnsandbox.wsgi.application'


# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

and finally the flglnsandbox/templates/admin/base_site.html:

{% extends "admin/base.html" %}

{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block branding %}
<div id="site-name"><a href="{% url 'admin:index' %}">Polls Stuff</a>MAMBOJUMBO</div>
{% if user.is_anonymous %}
  {% include "admin/color_theme_toggle.html" %}
{% endif %}
{% endblock %}

{% block nav-global %}{% endblock %}

I did check everything double, looked through Stackoverflow, this Forum and made sure I try what I possibly can to verify everything is correct.

This said, I’m not 100% sure where I should see now “Polls stuff” (Which I named this way just to make it more obvious to me) and no matter where I look, nothing changed :frowning:

Maybe someone has an idea, as I would love to resolve this first before moving on :slight_smile:

Thank you very much for your attention and help,

Flo

Taking a look at this video (particularly starting at timestamp 20:04) might help. When the person refreshes their page, they show exactly what you should see change for that part of the tutorial.

Also, make sure you have your server running to see the admin screen:
python manage.py runserver

Thank you very much!

That is where I suspected the change, but unfortunately it doesn’t show. I restarted the server, I cleared the cache, used incognito window etc… But it won’t change the template unfortunately and I can’t seem to find the reason :frowning:

I also found an old entry where it was mentioned that the order of INSTALLED_APPS matters. I confirmed as well here that this should be fine.

Running out of options :confused:

Edit: and the log of the Server also shows no errors:

[21/May/2024 17:17:04] "GET /admin/ HTTP/1.1" 200 7300
[21/May/2024 17:17:04] "GET /static/admin/css/base.css HTTP/1.1" 200 21544
[21/May/2024 17:17:04] "GET /static/admin/css/dark_mode.css HTTP/1.1" 200 2682
[21/May/2024 17:17:04] "GET /static/admin/css/dashboard.css HTTP/1.1" 200 441
[21/May/2024 17:17:04] "GET /static/admin/css/nav_sidebar.css HTTP/1.1" 200 2810
[21/May/2024 17:17:04] "GET /static/admin/js/nav_sidebar.js HTTP/1.1" 200 3063
[21/May/2024 17:17:04] "GET /static/admin/js/theme.js HTTP/1.1" 200 1943
[21/May/2024 17:17:04] "GET /static/admin/css/responsive.css HTTP/1.1" 200 17905
[21/May/2024 17:17:04] "GET /static/admin/img/icon-addlink.svg HTTP/1.1" 200 331
[21/May/2024 17:17:04] "GET /static/admin/img/icon-changelink.svg HTTP/1.1" 200 380
Not Found: /favicon.ico
[21/May/2024 17:17:04] "GET /favicon.ico HTTP/1.1" 404 2222

The issue here is that you have this new “templates” directory inside the “inner” flglnsandbox and not the “project-level” or “outer” flglnsandbox directory.

This new “templates” directory should be at the same level as your “flglnsandbox” and “polls” directory.

From the docs at Writing your first Django app, part 7 | Django documentation | Django

Create a templates directory in your project directory (the one that contains manage.py ).

1 Like

Ha! That was it. :slight_smile:

I got victim of VS Code and got a bit confused with the structure. I thought it was on the right place. Thank you very much! Now, I’m sorry that I’ve wasted your time for something this simple at the end.

Hi,
I’ve got the same problem but I do have my templates folder at the root level:


I have copied the base_site html file as described in the tutorial and added BASE_DIR / “templates” to settings.
Replaced {{ site_header|default:_('Django administration') }} with ">Polls Administration
But it still comes out with Django administration in the title.
Its clearly not picking up the path to my new template.
Any ideas what I have mucked up, things have been going pretty well since part 2 and I’m beginning to get my head round it all so some help appreciated!

Side note: This topic has been marked as solved, and therefore is unlikely to attract a lot of attention. I suggest you open a new topic for this.

When you do so, please include your actual TEMPLATES setting in your post.