1. Bruce Kroeze
  2. django-site-skins



Django Site Skins

The Point

This is a small library intended to allow one Django instance to serve several different domains, without relying on setting up separate settings files for each.

It can do this, while still providing the facility for each site to have its own "skin", while sharing a common site template directory for templates which don't need to be separately skinned.

Most of the time the skin directory will have very few files, along with a bit of CSS.

Can't you do this with separate settings files?

Of course, feel free. In practice, I dislike that solution, since I have found it difficult to maintain separate settings files in production, and a waste of server memory to load several Django instances when only one is needed, but your opinion may be different.

How does it work?

There are just two basic concepts.


First, the idea of a "skin". A skin is a collection of templates and associated assets such as CSS and images. These are intended to override the templates in the common "normal" django templates directory.

The Django Templating system will find the skin templates in preference to the common templates because you will add the skin loader to your TEMPLATE_LOADERS

At startup, the skin app will scan the directories listed in the SKIN_DIRS for all configured skins, and automatically make them available for sites.

See 'docs/INSTALL.rst' for code examples.

Skin Media

Skins also have their own "media_url", available via the template tag 'skin_media_url' in 'skin_tags'. It is fairly naive at this point, but it is SSL aware. For example, if you have your MEDIA_URL='http://media.example.com/', and the skin for the current domain is named 'foo', it will return "http://media.example.com/skins/foo/'

Here's a real-world example, from css in the header of a base template:

#maincontainer div#topcontainer { background: url({% skin_media_url images/masthead.jpg %}) no-repeat scroll top right; }

Defining a Skin

See the file 'example/skins/default/CONFIG.json'.

Essentially, just make a directory for your skins, make a sub-directory for your skin, and copy that config file into it. Edit as you please. The skin name will show up in the admin where you assign skins to domains.

Templates go directly in the same directory as the CONFIG.json file.

Activating a Skin

Server running, go to http://yoursite/admin/sites/site/

Make sure you have a domain defined for your site. When you click on the site, you'll see a "Skins" section, where you can pick from all auto-discovered skins and assign one to this domain.

After you save, whenever you hit that domain, that skin will be used by the template loader.