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.7
Tested with Python versions 2.7, 3.3, 3.4, 3.5
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:
pip intsall -r requirements-dev.txt py.test
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, is_tablet 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.3.tar.gz
.
File metadata
- Download URL: django-devicetype-templates-0.2.3.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 588eee2b3061decad53614108ef13ed5e0e197cc8ed21b5c677f2040acc22326 |
|
MD5 | f1a8c69be43f793a10927e4cd01cf92f |
|
BLAKE2b-256 | 539240facf190b46f6131328da3462b8c464dc14945279bf0b9dbb1d2d2ce796 |
File details
Details for the file django_devicetype_templates-0.2.3-py2.py3-none-any.whl
.
File metadata
- Download URL: django_devicetype_templates-0.2.3-py2.py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1ba695865edf1ec43da0d1c218b9e637e239993c6f072c1d7f3b44dfcf6e7f9 |
|
MD5 | e274adc8caaeecc4fd2c9cc4dd389b77 |
|
BLAKE2b-256 | 5f14da029ee4da523fb072ef65fd523c8c60ff0ad47b78eb21cb7bf34084544c |