Skip to main content
Travis

Travis


django-layers makes it possible to serve a set of templates and static resources as defined in settings.py. This means you can serve different HTML, Javascript and CSS to eg. basic mobile devices, smart phones and desktop browsers. These template sets (aka layers) also stack, so if you create foo.html for basic devices it is automatically available for desktop browsers as well. You can override foo.html for desktop browsers.

Installation

  1. Install or add django-layers to your Python path.

  2. Add layers after django.contrib.static to your INSTALLED_APPS setting.

  3. Ensure the app that you will be creating layers for appears first in INSTALLED_APPS else template override won’t work.

Example

Note: there is a working example in the example subdirectory.

We have sites example.com, basic.example.com and smart.example.com. Each of the sites have their own settings.py, thus different Django processes.

Directory structure

templates
    - basic
        - foo.html (1)
        - bar.html (2)
    - smart
        - bar.html (3)
    - web
        - bar.html (4)

static
    - basic
        - foo.css (5)
        - bar.css (6)
    - smart
        - bar.css (7)
    - web
        - bar.css (8)

Settings

We define an “inheritance” hierarchy.

  • Desktop settings has LAYERS = {'layers': ['basic', 'web']}.

  • Basic settings has LAYERS = {'layers': ['basic']}.

  • Smart settings has LAYERS = {'layers': ['basic', 'smart']}.

All settings require loaders and finders to be set. The order is important.

INSTALLED_APPS = (
    'myapp',
    'layers',
    ...
)

TEMPLATE_LOADERS = (
    'layers.loaders.filesystem.Loader',
    'django.template.loaders.filesystem.Loader',
    'layers.loaders.app_directories.Loader',
    'django.template.loaders.app_directories.Loader',
)

STATICFILES_FINDERS = (
    'layers.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'layers.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

Template results

Static results

Overriding templates from other apps

The normal template resolution rules apply. Creating eg. templates/web/registration/login.html will override the login page for web only.

Collectstatic

Collectstatic remains unaffected. The collector delegates to finders, so all layer aware resources end up with partial paths under the STATIC_ROOT directory.

Authors

  • Hedley Roos

Changelog

0.2

  1. Inevitable package rename.

0.1

  1. Initial release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-layers-hr-0.3.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_layers_hr-0.3-py2.7.egg (17.1 kB view details)

Uploaded Egg

File details

Details for the file django-layers-hr-0.3.tar.gz.

File metadata

File hashes

Hashes for django-layers-hr-0.3.tar.gz
Algorithm Hash digest
SHA256 1ae99886bba7f5fb440948a258fd171f87545e6e95cd877e94f3980aaef6eaf0
MD5 6ce9a15a14f7f0e6be6ff90aec809e9c
BLAKE2b-256 336eaa9ba326cddf25de108fcb6aca4679dd9e3b1908f0e5e069242457e19bdd

See more details on using hashes here.

File details

Details for the file django_layers_hr-0.3-py2.7.egg.

File metadata

File hashes

Hashes for django_layers_hr-0.3-py2.7.egg
Algorithm Hash digest
SHA256 862b29872cf20ac0edda1b5e50df9f6ccf412826c6bb9797fddbb24224f6505a
MD5 acd25d04e46722290adcc1057954fc00
BLAKE2b-256 33774ac1c506579e8e06bab7a254864bd39cd7c4f6e407fe96ed7a6d291c5879

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page