Skip to main content

Django library to serve different templates for different device types

Project description

django-devicetype-templates is a library that detect device type by browser’s user agent string and serves different templates for each type.

If standard responsive layouts does not fit all of your needs and if you do not want to use some hacky template loaders with thread locals, you may find this library useful.

Requirements

Installation

Install from PyPi:

pip install django-devicetype-templates

Install development version to virtualenv:

git clone https://github.com/whit/django-devicetype-templates.git
cd django-devicetype-templates
python setup.py develop

Run tests:

python setup.py nosetests

Configuration

Add middleware:

MIDDLEWARE_CLASSES = (
    ...
    'devicetype.middleware.DeviceTypeMiddleware',
)

If you need to use some variables in your templates, you can add devicetype context processor:

TEMPLATE_CONTEXT_PROCESSORS = (
    ...
    'devicetype.context_processors.devicetype',
)

Then, in templates will be available these variables: devicetype, is_mobile and big_resolution (not implemented yet).

Other settings

DEVICETYPE_TEMPLATE_PREFIX

Prefixes are variable. When you need prefix template file name, use something like tablet-. If you want to have device-specific templates in subfolders, you can use tablet/ prefix for example.

Default:

{
    'desktop': '',
    'mobile': 'mobile/',
    'tablet': 'tablet/',
}

DEVICETYPE_PREFIX_BASENAME

When you use folder-like prefix, like tablet/ and mobile/, with this setting you can select how subfolders will be detected.

With DEVICETYPE_PREFIX_BASENAME = False (default):

tablet/base.html
tablet/app/app_base.html
tablet/layout/three-cols.html
...

With DEVICETYPE_PREFIX_BASENAME = True:

tablet/base.html
app/tablet/app_base.html
layout/tablet/three-cols.html
...

DEVICETYPE_MOBILE_PATTERNS and DEVICETYPE_TABLET_PATTERNS

You can override default search patterns. It search in tablet patterns first.

Build status

Master branch:
Travis CI - Distributed build platform for the open source community

Project details


Download files

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

Source Distribution

django-devicetype-templates-0.1.9.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-devicetype-templates-0.1.9.tar.gz.

File metadata

File hashes

Hashes for django-devicetype-templates-0.1.9.tar.gz
Algorithm Hash digest
SHA256 755f69fcfd1ce4c6b9744b54750c51795702f922a0ef460701f553f72652551c
MD5 2e6e4ddd7c305b8f7d4afcf8f96a0ea3
BLAKE2b-256 0a160f468badc656f530db422bd36d4382bb688841b8a97dd5ea6cb25ff45524

See more details on using hashes here.

File details

Details for the file django_devicetype_templates-0.1.9-py27-none-any.whl.

File metadata

File hashes

Hashes for django_devicetype_templates-0.1.9-py27-none-any.whl
Algorithm Hash digest
SHA256 fc3e4c44e5b29390011126c61ab74ef7a4d68a1bec707a74f7b8b29c529d8d9c
MD5 d76418acc328b482ac899d23ef1dad4f
BLAKE2b-256 da44770524ba091fff4c985ff30e0653d484f3cc11f969b92372d26f26ae287c

See more details on using hashes here.

Supported by

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