Layout and global.css files

179 views
Skip to first unread message

Gregory Strydom

unread,
Aug 22, 2012, 9:41:45 PM8/22/12
to django...@googlegroups.com
Could anyone perhaps tell me where i could find the layout.css and global.css for the base admin site?

Ive tried looking through C:/Python26/site-packages/django but cant seem to find anything. What i am trying to do is just change colour where it say Users, Groups, Sites etc in the django admin. I managed to change the header colors so far but was told i need to edit layout and global.css to change the other colors.

Thanks very much for any help with this!

Jeff Tchang

unread,
Aug 22, 2012, 9:43:58 PM8/22/12
to django...@googlegroups.com
I see some stuff under:

/python/lib/python2.6/site-packages/django/contrib/admin/static/admin/css



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/N9aDIJzmHngJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Melvyn Sopacua

unread,
Aug 22, 2012, 9:54:16 PM8/22/12
to django...@googlegroups.com
On 23-8-2012 3:41, Gregory Strydom wrote:
> Could anyone perhaps tell me where i could find the layout.css and
> global.css for the base admin site?
>
> Ive tried looking through C:/Python26/site-packages/django but cant seem to
> find anything.

You shouldn't edit anything there - it will be lost when you upgrade.
The base procedure is described here:
<https://docs.djangoproject.com/en/1.4/intro/tutorial02/#customize-the-admin-look-and-feel>

For the css and js bits, read these top to bottom:
<https://docs.djangoproject.com/en/1.4/howto/static-files/>
<https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/>

The short version is to copy the files to the appropriate location
whether it be the TEMPLATE_DIRS or STATIC_ROOT and edit those files. The
long version is that you should thoroughly understand how static files
work - it's a recurring issue on the list and it's one of those things
that has to sink in and then you get it. If you don't get it, then lots
of time and energy is wasted on "trying if this works".

--
Melvyn Sopacua

Mike Dewhirst

unread,
Aug 22, 2012, 10:17:18 PM8/22/12
to django...@googlegroups.com
I have solved this in a cack-handed way and would like to learn how to
do it correctly.

I had trouble getting my own css files to work in the admin overriding
the contrib.admin styles because the admin base.css kept being used
instead of mine when I used the extrastyle block. Here is my
base_site.html template ...

{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'X' %}{% endblock %}
{% block extrastyle %}{% endblock %}
{% block userstyle %}<link rel="stylesheet" type="text/css"
href="/static/css/darker.css" />{% endblock %}
{% block branding %}
<h1 id="site-name">{% trans 'X Administration' %}</h1>
{% endblock %}
{% block nav-global %}{% endblock %}
{% block extrahead %}{% endblock %}

You can see the "foreign" userstyle block there. That is where I had to
put my css to get it used in the right cascade sequence over the top of
the real thing. I think the extrastyle block is for extra styles rather
than replacement styles.

I wrote a script to patch the admin base.html to insert that userstyle
block and that works. But adjusting the admin base.html is not nice.
Hence I would like to discover how it should be done.

Here is my patch_admin_base.py script ...

"""
patch django-admin base.html to include a userstyle block
"""

project = "x"
srvroot = "/srv/www"
vws_root = "%s/%s" % (srvroot, project)
app_root = "%s/%s" % (vws_root, project)

import os
import sys

if app_root not in sys.path:
sys.path.insert(0, app_root)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "%s.settings" % project)

from django.contrib import admin

flag = '{% block extrastyle %}{% endblock %}'
patch1 = '{# userstyle inserted by md #}\n'
patch2 = '{% block userstyle %}{% endblock %}\n'
base_template = 'templates/admin/base.html'
done = False
pth =
os.path.split(str(admin).split()[-1].split("'")[-2].replace("\\","/"))[0]
template = '%s/%s' % (pth, base_template)
if os.path.isfile(template):
lines = list()
with open(template, "r") as base:
lines = base.readlines()
done = patch2 in lines
if not done:
with open(template, "w") as base:
for line in lines:
base.write(line)
if flag in line:
base.write(patch1)
base.write(patch2)
done = True
if done:
print('\n%s patched' % template)
else:
print('\n%s not patched' % template)
else:
print('\n%s already patched' % template)
else:
print('\nbase.html not found')


>
> Thanks very much for any help with this!
>

Gregory Strydom

unread,
Aug 22, 2012, 10:24:19 PM8/22/12
to django...@googlegroups.com


Thanks very much for the replies, this really helps alot!
Reply all
Reply to author
Forward
0 new messages