django-mobler

User-Agent-based mobile device detection for Django

MIT License

Downloads
37
Stars
9
Committers
1

django-mobler

django-mobler is a User-Agent-based mobile device detection app for Django.

Installation

django-mobler can be installed in any number of the usual ways:

easy_install django-mobler
pip install django-mobler
pip install -e git+git://github.com/dmpayton/django-mobler.git#egg=django-mobler
git clone git://github.com/dmpayton/django-mobler.git
cd django-mobler
python setup.py install

etc...

Usage

Mobler requires only a couple changes to your settings.py in order to function:

  • Add mobler to INSTALLED_APPS.
  • Add mobler.middleware.MobileDetectionMiddleware to MIDDLEWARE_CLASSES (preferably near the top).
  • Set MOBILE_DOMAIN to the full domain of your mobile site.

Requests to your site from a mobile device will now be redirected to the same URL path and query string on your mobile site.

Override

To override the redirect, visit any page on the full site with ?mobler-override=1. This will set a cookie and prevent the redirect from taking place on subsequent page views.

If your mobile site is built in Django, mobler includes a helper template tag to generate the override URL for the same page on the full site.

Usage:

{% load mobler_tags %}
<a href="http://www.example.com{% full_site_override request %}">Full Site</a>

If you are on http://m.example.com/foo/bar/?fizz=buzz, the tag will return /foo/bar/?fizz=buzz&mobler-override=1.

Settings

MOBILE_DOMAIN URL of your mobile site, e.g., http://m.example.com Required

MOBLER_UA_STRINGS List of substrings to look for in the User-Agent. Default: ('Android', 'BlackBerry', 'IEMobile', 'Maemo', 'Opera Mini', 'SymbianOS', 'WebOS', 'Windows Phone', 'iPhone')

MOBLER_COOKIE_NAME Name of the override cookie and GET parameter Default: mobler-override

MOBLER_COOKIE_AGE How long the override cookie should live Default: 60*60*24*31 (31 days)

MOBLER_PRESERVE_URL Whether or not to preserve the URL when redirecting to the mobile site (if False, users will be redirected to your mobile homepage) Default: True

Testing

python manage.py test mobler

Special Thanks

django-mobler was inspired by django-browsecap.