Search code examples
pythondjangotemplatespycharmadmin

Django Admin Template OverRide Issue


I'm currently using Django 2.0.5 for Pycharm-2018.1.2 I recently started working on my first project which basically requires me to work on the admin part of Django. I've managed to get my project working but I'm having issues with overriding the Admin Template for some reason... I've followed a few tutorials and read a few articles on this forum but i still couldn't find out what's going wrong..

Here's what i have in my '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/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '-r3^d48%3rh7xrecgl9*3r(had#9nz%7nsn$y%h&o$3_ary*q7'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'Bugs.apps.BugsConfig',
    '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 = 'BugReport.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 = 'BugReport.wsgi.application'


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


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


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


STATIC_URL = '/static/'

I have a directory named templates->admin->base_site.html I have also created a folder called static which contains 3 other directories (css, html,js)

The base_site.html has the following html code

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

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

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

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

Even then, The main admin login page still shows Django Administration

Where am i going wrong? How Do i Change the templates? Is there another way? If you need any more details, do let me know and I'll post it as soon as possible.

P.S: please do bare in mind that I'm still a beginner and I dont know a lot about the technical aspects yet.

I haven't hosted the website yet.

Update I have One App Called Bugs which contains The admin.py


Solution

  • Instead of {{ site_header|default:_('Bug administration') }} just write Bug administration.