Overview

django-flext

A Django application that provides flexible template locations, allowing for transparent alternate templates.

The template location can be set by middleware or request signals to modify the template location for individual requests.

Installation

Install flext then modify your project's settings module so that the flext template loader is first. For example:

from django.conf.global_settings import TEMPLATE_LOADERS

TEMPLATE_LOADERS = (
    'django_flext.loaders.FlexibleLoader'
) + TEMPLATE_LOADERS

Usage

A basic installation doesn't change how anything works in your project. To actually use flext, you'll need to set (and unset) the flexible template location by using middleware or request signals.

If you like reading code, view the source of the included middleware for an example.

The following functions can be used to alter the template directories which the flexible template loader uses:

django_flext.add_dirs(template_dirs, loader=None)

Adds a list of template directories to use.

The file system template loader will be used unless an alternate loader is provided.

django_flext.reset()

Reset the flexible template loader so no template directories are used.

Included Middleware

django_flext.middleware.MobileDomainMiddleware

This middleware adds one or more mobile-only template directories if the user is visiting from a mobile domain.

Expects a MOBILE_TEMPLATE_DIRS setting which should be a tuple of filesystem locations where the mobile template directories can be found.

To customise what is considered a mobile domain, set the optional MOBILE_DOMAIN_MATCH setting to a regular expression string (or object). By default, any host name starting with "m." or "mobile." is considered a mobile domain.