Skip to main content
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.7
Last Update: 11/17/2013

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.middleware.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.middleware.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.

If you want to have some items not triggered by the middleware (for example iPad) then add a settings called MOBI_USER_AGENT_IGNORE_LIST and add the item to the list.

MOBI_USER_AGENT_IGNORE_LIST = ['ipad',]

If you want to distinguish tablet devices from phones, then set MOBI_DETECT_TABLET = True and use request.tablet attribute

{% if not request.mobile or request.tablet %}
<p>This section enabled only for descktop and tablets</p>
{% endif %}




Using the mobi.middleware.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.middleware.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



Metadata

Release files for django-mobi2 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-mobi2 1.0.2
File Size Uploaded Provenance Actions
django-mobi2-1.0.2.tar.gz 6.2 kB Without provenance Details for django-mobi2-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-mobi2 1.0.2
File Interpreter ABI Platform Actions
django_mobi2-1.0.2-py2.py3-none-any.whl Python 3, Python 2 none any Details for django_mobi2-1.0.2-py2.py3-none-any.whl

Total release size: 12.8 kB

Release files / django-mobi2-1.0.2.tar.gz

Download URL django-mobi2-1.0.2.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3bca5ed675f029f85f36574cc7befda4b7380e8a88ddee165099328e3eca7e07
BLAKE2b-256 checksum
How to use checksums
295acf05ee72529c4a73b6d649ea146d973e23185b94480a1ea5b17d724e2999
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_mobi2-1.0.2-py2.py3-none-any.whl

Download URL django_mobi2-1.0.2-py2.py3-none-any.whl
Size 6.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ce8cd53c197a0068dc30e4fc660834f58c3254bb1afe724d90210781f219fac2
BLAKE2b-256 checksum
How to use checksums
5558856a2bcb732850491fbcdb6ba3d823a27e1c514a69301f988f37901cbaff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-mobi2 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page