Skip to content

Detect request's mobile user agents using the Mobileesp lib

License

Notifications You must be signed in to change notification settings

mhb11/django-mobileesp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Mobileesp

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

This is an alternative to django-user_agents project.

Install

pip install django_mobileesp

Usage

Add to your 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,
}

Adapt the DETECT_USER_AGENTS to your needs:

  • Key: name of attribute to add to each request instance.
  • Value: bounded method to be invocked on each request by UserAgentDetectionMiddleware.
    • Can be combined with &(AND) and |(OR) operands.
    • Read the mobileesp docs to check all the available methods.

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

About

Detect request's mobile user agents using the Mobileesp lib

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%