Skip to main content

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

DEBUG_DEVICETYPE_NOCOOKIE

For development purposes if you want to switch user agents oftenly. Cookie max age wil be set to 5 seconds.

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

Metadata

Release files for django-devicetype-templates 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-devicetype-templates 0.2.3
File Size Uploaded
django-devicetype-templates-0.2.3.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-devicetype-templates 0.2.3
File Interpreter ABI Platform
django_devicetype_templates-0.2.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 13.0 kB

Release files / django-devicetype-templates-0.2.3.tar.gz

Download URL django-devicetype-templates-0.2.3.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
588eee2b3061decad53614108ef13ed5e0e197cc8ed21b5c677f2040acc22326
BLAKE2b-256 checksum
How to use checksums
539240facf190b46f6131328da3462b8c464dc14945279bf0b9dbb1d2d2ce796
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_devicetype_templates-0.2.3-py2.py3-none-any.whl

Download URL django_devicetype_templates-0.2.3-py2.py3-none-any.whl
Size 8.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c1ba695865edf1ec43da0d1c218b9e637e239993c6f072c1d7f3b44dfcf6e7f9
BLAKE2b-256 checksum
How to use checksums
5f14da029ee4da523fb072ef65fd523c8c60ff0ad47b78eb21cb7bf34084544c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page