Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django 1.9 + customizing admin interface

I am using Django1.9 & trying to override admin interface.

I referred following link to override admin header

http://stackoverflow.com/questions/4938491/django-admin-change-header-django-administration-text

As mentioned in post, my directory/file structure is src->templates->admin->base_site.html

base_site.html

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

{% block title %}Personal Site{% endblock %}

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

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

But this page is not getting called. I copied base_site.html code from https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/base_site.html

& made changes in title.

I know, I can configure admin header in django, but this is not I am looking for. My long-term goal is to configure entire admin UI. So please explain me how I can make this custom template page get called.

Here is my template settings :

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
           os.path.join(BASE_DIR,'templates'),
        ],
        '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',
            ],
            'loaders':[
                    'django.template.loaders.filesystem.Loader',
                    'django.template.loaders.app_directories.Loader'
            ]
        },
    },
]

Thanks Aniruddha

like image 954
Aniruddha Avatar asked Jan 13 '16 01:01

Aniruddha


1 Answers

configure project's admin template directories at the contrib/admin/templates/admin directory.

For override -Create a customadmin directory in templates directory.

  • You can also customize the 'loaders' option, by adding the 'django.template.loaders.filesystem.Loader' (must be written before )
  • 'django.template.loaders.app_directories.Loader'.

This will load the custom templates before default.

Create directories in customadmin and name these as of app, if you want to override for app.

In above subdirectories, create directories for models and name them as model, for overriding the model.

Create your custom extended template (the html file in most cases) in desired directory.

Congratulations. You have extended the default provided admin.

like image 136
Anil Avatar answered Sep 23 '22 02:09

Anil