This package provides a decorator that allows you to specify a template path for regular desktop browsers, and a template path for mobile browsers.
Right now "user agent" means "mobile vs desktop", but that could change in the future (for example, caring if the browser is a full mobile browser, like Mobile WebKit, or a less capable browser like a WAP browser or Opera Lite).
It is meant to be used with django_annoying.
The requirements are as follows:
Minidetector is used to do the mobile vs desktop detection. However, the official site does not provide a setup.py file.
I like using PIP, and there is a fork of minidetector with a setup.py file: http://github.com/brosner/minidetector
To install this version of minidetector with PIP:
$ pip install -e git://github.com/brosner/minidetector.git#egg=minidetector
Hooking this into your Django project
minidetector.Middlewarehas to appended to your
In your views:
from django_user_agent_detector import ua_detector
Using this in your Django views
Use it like:
@render_to() @ua_detector(standard="template_name") def view_function(response): return dict()
@render_to() @ua_detector(standard="template_name", mobile="template_name_mobile") def view_function(response): return dict()
@ua_detector must come below the
How I use this in my Django projects
I like to have app specific templates, stored like
project/ APPNAME/ templates/ APPNAME/ template_name.html mobile/ template_name.html
Then I render my views like so:
@render_to() @ua_detector(standard="APPNAME/template_name", mobile="APPNAME/mobile/template_name") def view_function(response): return dict()
I tried it, and I didn't like the high setup costs, there seemed to be some pretty significant bugs, and I couldn't use