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
Django >= 1.3
It uses process_template_response middleware method, so your views should returns TemplateResponse.
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-devicetype-templates-0.2.0.tar.gz
.
File metadata
- Download URL: django-devicetype-templates-0.2.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e02801d56b2972844591df99e2188c0c8d5412490f714bf6845d53b3b281bed0 |
|
MD5 | 3e3d0714d105fde6e6aad3a7fb9be78e |
|
BLAKE2b-256 | dc0955bd079c81861dafd12f4a8d9a4fa9e57bf78af933022605c8322ac38ec6 |
File details
Details for the file django_devicetype_templates-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_devicetype_templates-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb2ff0c9b84eb628f41edc5476bff0a49cb10c03a83b7b88dae5fdab6ceaaaa2 |
|
MD5 | 7906110f50b480637c9df9b4bcaa638b |
|
BLAKE2b-256 | 4cbd96d435fb24d932e48c0820eccb6f89d41ea2f1cb421619c92cade5bd5609 |