Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.10: base_site.html override not working

I am creating a site in Django with a custom view, and want to link to that view on the admin page. But even though I've followed the directions to override base_site.html in the Django tutorial, nothing changes. No matter if input the simplest change:

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

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

 {% block branding %}
 <h1 id="site-name"><a href="{% url 'admin:index' %}">Test</a></h1>
 {% endblock %}

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

Or even something very drastic, where I don't extend the base.html at all:

<h1>Test</h1>

My directories are exactly as they should be, with the new base_site.html inside them:

└─myproject
    └── myproject
        └── templates
            └── admin
                └── base_site.html

This is my current settings.py:

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = <mysecretkey>

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'easy_thumbnails',
   'filer',
   'mptt',
   'myapp',
]

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 = 'myproject.urls'

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',
           ],
       },
   },
]

WSGI_APPLICATION = 'myproject.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.10/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/1.10/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

# Thumbnail settings for retina displays
THUMBNAIL_HIGH_RESOLUTION = True

# Thumbnail processing

THUMBNAIL_PROCESSORS = (
    'easy_thumbnails.processors.colorspace',
    'easy_thumbnails.processors.autocrop',
    #'easy_thumbnails.processors.scale_and_crop',
    'filer.thumbnail_processors.scale_and_crop_with_subject_location',
    'easy_thumbnails.processors.filters',
 ) 

I've restarted the server, as well as used different browsers, and none of my changes show up.

Am I doing something wrong anywhere, or are the instructions given by the tutorial just plain incorrect?

like image 339
eijen Avatar asked Dec 03 '22 22:12

eijen


1 Answers

The Django tutorial is actually correct and works fine. Here's the issue: The "templates" directory is a child of the first "mysite" directly, not the second.

This is actually made very clear in the tutorial but is easy to get confused and place the "templates" directly within the wrong directory.

enter image description here

In other words, you want "templates" to be here:

mysite/templates

and not here:

mysite/mysite/templates

Tutorial step #7 makes this clear. Here's a screen shot of the directory structure as it should be at that point in time:

enter image description here

Just move your "templates" directory up one level and all should be well.

like image 101
martin's Avatar answered Dec 11 '22 17:12

martin's