Skip to main content

Django middleware and view decorator to detect phones and small-screen devices

Project description

Author: Ken Cochrane
Fork of: http://minidetector.googlecode.com
Fork Description: I reorganized the code, added caching, and made a few tweaks here and there.
Description: Django middleware and view decorator to detect phones and small-screen devices
Version: 0.1
Last Update: 7/4/2011

Requirements:
-------------
Django 1.1 or newer
Django caching to be enabled if you want to cache the objects

How to use:
-----------
Using django-mobi is very simple. Simply place the mobi package into your project's path, and then do one of the following:


Using the mobi.MobileDetectionMiddleware Middleware
---------------------------------------------------
This middleware will scan all incoming requests to see if it is a mobile device. If it is it will set the request.mobile property to True.

To use all you have to do is add mobi.MobileDetectionMiddleware to your MIDDLEWARE_CLASSES tuple in your settings.py

Then in your view you can check request.mobile - if it's True then treat it like a small screen device. If it's False then it's probably a desktop browser, or a spider or something else.


Using the mobi.MobileRedirectMiddleware Middleware
---------------------------------------------------
This middleware will scan all incoming requests to see if it is a mobile device, if so it will redirect the request to a different URL. This is good if you want to force all mobile traffic to a mobile only version of your site.

To use all you have to do is add mobi.MobileRedirectMiddleware to your MIDDLEWARE_CLASSES tuple in your settings.py, and also add MOBI_REDIRECT_URL = "http://example.mobi" where http://example.mobi is the website you want to redirect all mobile traffic.


Not using the Middleware
------------------------
If you only have certain views that need the distinction, you can choose not to search every request you receive. All you need to do is wrap the relevant views like this:

from mobi.decorators import detect_mobile

@detect_mobile
def my_mobile_view(request):
if request.mobile:
#do something with mobile

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-mobi-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file django-mobi-0.1.1.tar.gz.

File metadata

  • Download URL: django-mobi-0.1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-mobi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f0191fbe1b643cc95b2889a6b3e3c69e8984745ea7e5d300f2160c83c09f3a6e
MD5 19bb1f7a24b7f8647e76f3c0a3eb521e
BLAKE2b-256 d6b501cd9e1489df3cd8d7d429678264c700d0f434c9ffeb34e1989750b09b75

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page