Programming in almost language

This is the site where you may share your knowledge and experience to eachother..

  • Categories

  • LinkedIn

  • Tweet Me

  • My footsteps

Django

Posted by Praveen Kumar on December 22, 2008

Customize the admin look and feel

Clearly, having “Django administration” at the top of each admin page is ridiculous. It’s just placeholder text.

That’s easy to change, though, using Django’s template system. The Django admin is powered by Django itself, and its interfaces use Django’s own template system. (How meta!)

Open your settings file (mysite/settings.py, remember) and look at the TEMPLATE_DIRS setting.

TEMPLATE_DIRS is a tuple of filesystem directories to check when loading Django templates.

It’s a search path.

By default, TEMPLATE_DIRS is empty. So, let’s add a line to it, to tell Django where our templates live:

TEMPLATE_DIRS = (“/home/my_username/mytemplates”, # Change this to your own directory.)

Now copy the template admin/base_site.html from within the default Django admin template directory

(django/contrib/admin/templates) into an admin subdirectory of whichever directory you’re using in TEMPLATE_DIRS.

For example,

if your TEMPLATE_DIRS includes “/home/my_username/mytemplates”, as above, then copy django/contrib/admin/templates/admin/base_site.html to /home/my_username/mytemplates/admin/base_site.html.

Don’t forget that admin subdirectory.

Then, just edit the file and replace the generic Django text with your own site’s name as you see fit.

Note that any of Django’s default admin templates can be overridden.

To override a template, just do the same thing you did with base_site.html — copy it from the default directory into your custom directory, and make changes.

Astute readers will ask: But if TEMPLATE_DIRS was empty by default, how was Django finding the default admin templates? The answer is that, by default, Django automatically looks for a templates/ subdirectory within each app package, for use as a fallback. See the template loader documentation for full information below

Loader types

By default, Django uses a filesystem-based template loader, but Django comes with a few other template loaders, which know how to load templates from other sources.

These other loaders are disabled by default, but you can activate them by editing your TEMPLATE_LOADERS setting. TEMPLATE_LOADERS should be a tuple of strings, where each string represents a template loader. Here are the template loaders that come with Django:

django.template.loaders.filesystem.load_template_sourceLoads templates from the filesystem, according to TEMPLATE_DIRS.django.template.loaders.app_directories.load_template_source

Loads templates from Django apps on the filesystem. For each app in INSTALLED_APPS, the loader looks for a templates subdirectory. If the directory exists, Django looks for templates in there.

This means you can store templates with your individual apps. This also makes it easy to distribute Django apps with default templates.

For example, for this setting:

INSTALLED_APPS = (‘myproject.polls’, ‘myproject.music’)

…then get_template('foo.html') will look for templates in these directories, in this order:

  • /path/to/myproject/polls/templates/foo.html/path/to/myproject/music/templates/foo.html

Note that the loader performs an optimization when it is first imported: It caches a list of which INSTALLED_APPS packages have a templates subdirectory.

django.template.loaders.eggs.load_template_sourceJust like app_directories above, but it loads templates from Python eggs rather than from the filesystem.

Django uses the template loaders in order according to the TEMPLATE_LOADERS setting. It uses each loader until a loader finds a match.

For enabling style sheet in Django

(r’^static_media/(?P<path>.*)$’, ‘django.views.static.serve’,{‘document_root’: ‘media’}), add this lines in your urls.py

ADMIN_MEDIA_PREFIX = ‘/media/’ enabled this lines in your settings.py and put your css file at the same level of your site folder suppose you have created a new site mysite. it will create folder mysite inside that there you would keep your application. create media folder at same level of your site and put your css/style.css

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: