Customizing CSS

409 views
Skip to first unread message

NENAD CIKIC

unread,
Jan 28, 2012, 11:47:26 AM1/28/12
to django-admin-tools
Hello, I am new to django and web development. I have followed the
tutorial and read a book about django, and so I have started my first
django project.
I have decided to stick with the admin interface for this first
project. Nontheless I want to customize a bit the look. I have managed
to create a template folder under my application and to change for
example base.html. Doing so I have left unchanged the original
base.html in the python/django path.
I am struggling to do the same for css files. I am aware that there
are special issues with static files for development and deployment
servers, but I am concerned at the moment only about development (i.e.
using runserver command). The only thing I have managed to do is to
change the base.html and reference mybase.css, where unfortunately
mybase.css has to stay in the C:\Python27\Lib\site-packages\django
\contrib\admin\media\css
I do not want this if it is possible, becasue for instance it's more
difficult to backups or version control on files that are not under
the project path.

Thanks
Nenad

Mikhail Korobov

unread,
Jan 28, 2012, 12:30:32 PM1/28/12
to django-ad...@googlegroups.com
Hi Nenad,

If you're using django-admin-tools then you can use its http://django-admin-tools.readthedocs.org/en/latest/customization.html#customizing-the-theme and override the required css rules in this extra file.

An another option which is not specific to django-admin-tools is to use django.contrib.staticfiles features: files in STATICFILES_DIRS take precedence over files found in app's static folders with the default config; both standard django admin and django-admin-tools are just an apps so you can override their static files by creating the same files (with the same paths) in your project's static folder.

E.g. if you want to override the base.css and your staticfiles folder is myproject/static, create the myproject/static/admin/css/base.css file and it will be used instead of standard admin's base.css. This works the same way as overriding templates (STATICFILES_DIRS == TEMPLATE_DIRS, STATICFILES_FINDERS == TEMPLATE_LOADERS). 

You question seems to be unspecific for django-admin-tools. You may want to post such questions to https://groups.google.com/forum/#!forum/django-users because django-users list has a larger audience and chances you'll get an answer for a general django question is better there.

NENAD CIKIC

unread,
Jan 28, 2012, 2:56:03 PM1/28/12
to django-admin-tools
OK, many thanks
I will try yours suggestion.

NENAD CIKIC

unread,
Jan 29, 2012, 4:12:13 AM1/29/12
to django-admin-tools
I have experimented with admin-tools, and I like it. I think I will
use it. I have managed to use my dashboard.html using yours
suggestions. I have still problems with dashboard.css.

I see that by default django take the dashboard.css from : C:
\Python27\Lib\site-packages\admin_tools\dashboard\static\admin_tools
\css
With the following settings
import os
ABSOLUTE_PATH = '%s/' % os.path.abspath(
os.path.dirname(locals()['__file__'])).replace('\\', '/')

STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/
static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
ABSOLUTE_PATH + 'static',
)

I manage to use my base.css putting it in the following path
myproject\static\admin\css

Where should i put the dashboard.css? I have tried many path under
static, for example
myproject\static\admin_tools\dashboard\static\admin_tools\css
myproject\static\admin_tools\dashboard\css
and others but without luck.

Thanks
Nenad

NENAD CIKIC

unread,
Jan 29, 2012, 3:17:52 PM1/29/12
to django-admin-tools
OK, I got it myself.
I have set MEDIA_URL to myproject/static and i have created inside the
static folder the admin_tools/css

Nenad
Reply all
Reply to author
Forward
0 new messages