Skip to main content

Detect request's mobile user agents using the mobileesp lib.

Project description

settings.py

MIDDLEWARE_CLASSES = (
    ...
    'django_mobileesp.middleware.UserAgentDetectionMiddleware'
)

from django_mobileesp.detector import mobileesp_agent as agent

DETECT_USER_AGENTS = {
    'is_android': agent.detectAndroid,
    'is_ios': agent.detectIos,
    'is_windows_phone': agent.detectWindowsPhone,
    'is_mobile': agent.detectTierTablet | \
                      agent.detectTierIphone | \
                      agent.detectMobileQuick,
}

If you prefer more pythonic methods, you can user a wrapper agent as follows:

from django_mobileesp.detector import python_agent as agent

DETECT_USER_AGENTS = {
    'is_android': agent.detect_android,
    'is_ios': agent.detect_ios,
    'is_windows_phone': agent.detect_windows_phone,
    'is_mobile': agent.detect_tier_tablet | \
                      agent.detect_tier_iphone | \
                      agent.detect_mobile_quick,
}

Finally access the defined attributes in your views:

def view(request):
    if request.is_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-Mobileesp-1.0.1.tar.gz (10.5 kB view hashes)

Uploaded Source

Built Distribution

Django_Mobileesp-1.0.1-py2-none-any.whl (12.2 kB view hashes)

Uploaded Python 2

Supported by

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