Django Templates Part 2 Templates - base_site.html changes not reflected

I am trying to follow the Django tutorial part 2 and am stuck with the last part about templates. The problem I am facing is that I am changing base_site.html

and no changes are reflected in my site. I am using Python 3.4

In the tutorial, I created this file structure with a "templates" folder in the same directory as manage.py.

  • Textbook
    • Textbook
    • interrogates
    • Templates
      • admin
        • base_site.html
    • manage.py

Then I changed DIRS TEMPLATES 'to [os.path.join(BASE_DIR,'templates')]

settings.py:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
...
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls'
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'Tutorial.urls'
print(os.path.join(BASE_DIR, 'templates'))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(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',
],
},
},
]

      

Then I changed base_site.html like this:

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

{% block title %}{{ title }} | {{ site_title|default:_('My Admin Title') 
{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('My Admin Header') }}</a></h1>
{% endblock %}

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

      

Finally, I went to my site at:

http://localhost:8000/admin/

      

However, the title "Site Administration" still greeted me.

I checked the directory it was looking at (the print () line in settings.py) and the directory looks correct:

/home/<user>/Documents/DjangoProjects/Tutorial/templates

      

I've already checked this thread and others but didn't find anything useful. I believe I followed the tee tutorial, can any of you please help me understand how am I misinterpreting the tutorial? Or is it a documentation error?

+3


source to share


1 answer


There is nothing wrong with what you do, the problem is how the default

filter
pattern works .

This filter will give the value to the right of |

if the value to the left of is |

not passed to the template.

Since the django admin app passes the value for site_title

, the filter is not triggered by default.

If you did try to change the displayed title, you can set the valuesite_title

by configuring django admin (as you go further down the tutorial, you will learn more about configuring admin, which will make the link clearer).



If you want to check if the configuration is correct, you can change the template as follows:

{% block title %}
Foo: {{ title }} | {{ site_title|default:_('My Admin Title') }}
{% endblock %}

      

Then refresh your admin site and see the page title.

+4


source







All Articles