Source

django-user_agent_detector /

Filename Size Date modified Message
django_user_agent_detector
django_user_agent_detector.egg-info
33 B
2.5 KB
51 B
999 B

django-user_agent_detector

About

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.

Requirements

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:

@render_to()
@ua_detector(standard="template_name")
def view_function(response):
    return dict()

Or:

@render_to()
@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

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()

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.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.