Reputation: 71
I'm attempting to follow the Django Tutorial, Part 2, and getting stuck on the last part about templates. The problem I'm experiencing is that I'm changing base_site.html
and no changes are being reflected in my site. I am using Python 3.4
Per the tutorial, I created this file-structure with a "templates" folder in the same directory as manage.py.
Then, I modified TEMPLATES 'DIRS' 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 modified base_site.html to read:
{% 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 navigated to my website at:
http://localhost:8000/admin/
However, I'm still greeted by the title "Site Administration".
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 out this thread and others, but have not found anything helpful. I believe I've followed the tutorial to a tee, can any of you please help me understand how I'm interpreting the tutorial incorrectly? Or is this a documentation bug?
Upvotes: 3
Views: 544
Reputation: 174672
There is nothing wrong with what you are doing, the problem is how the template's default
filter works.
This filter will give the value on the right of the |
, if the value of the left of the |
is not passed to the template.
Since the django admin application is passing in a value for site_title
, the default filter is not triggered.
If you were really trying to change the title displayed, you can set the value of site_title
by customizing the django admin (as you move further in the tutorial, you will learn more about customizing the admin, which will make the link clearer).
If you just want to see if your setup is correct, you can change the template to the following:
{% block title %}
Foo: {{ title }} | {{ site_title|default:_('My Admin Title') }}
{% endblock %}
Then refresh your admin site and watch the title of the page.
Upvotes: 4