1. Ryan Wilcox
  2. django-user_agent_detector




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

  1. minidetector.Middleware has to appended to your MIDDLEWARE_CLASSES tuple.

  2. In your views: from django_user_agent_detector import ua_detector

Using this in your Django views

Use it like:

def view_function(response):
    return dict()


@ua_detector(standard="template_name", mobile="template_name_mobile")
def view_function(response):
    return dict()

Note that @ua_detector must come below the @render_to

How I use this in my Django projects

I like to have app specific templates, stored like


Then I render my views like so:

@ua_detector(standard="APPNAME/template_name", mobile="APPNAME/mobile/template_name")
def view_function(response):
    return dict()

Why not django-mobile?

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 django_annoying's render_to.