I'm new to Django and have encountered an error that really has me stumped. I'm just putting together a basic site and using the tutorial as a bit of a guide, but I've run into an issue regarding templates. I created a templates directory in the same directory as manage.py, created an admin directory within templates, and copied / pasted base_site.html within the admin directory as per the tutorial. I then changed a few of the headers, saved everything, restarted the server, and... nothing. No errors but no changes. It's as if I had done nothing. I've tried the various fixes suggested on here but none seem to work. It's as if the templates directory is not being found so the app is using the default. Here are the basics that I have right now:
Directory structure: Project>App, templates>admin>base_site.html, manage.py, etc.
In my settings.py:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
and
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',
],
},
},
]
and in base_site.html:
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('THIS IS WHAT I CHANGED') }}</a></h1>
I'm really hoping someone can point me in the right direction here.
This line:
{{ site_header|default:_('THIS IS WHAT I CHANGED') }}
is evaluating site_header
and if found False
, will output default. site_header
is a variable defined in AdminSite
class. There is no reason from what you describe for site_header
to be False
, so site_header
will be displayed, not the text you changed.
See Default filter
description:
DEFAULT
If value evaluates to False, uses the given default. Otherwise, uses the value.
For example:
{{ value|default:"nothing" }} If value is "" (the empty string), the output will be nothing.
Here: https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#default
There are ways to change site_header
, you can create a custom model based on AdminClass
and then define site_header
for this new instance. This means defining a new url as well.
Or you can set site_header:
django.contrib.admin.AdminSite.site_header = "New Header"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.