• About Us
  • Blog
  • Basket
  • Account
  • Sign In
  •  

Django

51Degrees Mobile Detector for python provides a middleware and a context processor designed to simplify the integration of the detection solution in Django platforms. This article assumes that Django is already being used.

Step 1: Install your preferred 51Degrees python mobile detection package using pip (the core package will be installed automatically as a dependency). For pattern matching:

pip install 51degrees-mobile-detector-v3-wrapper

For trie matching:

pip install 51degrees-mobile-detector-v3-trie-wrapper

Step 2: Add the 51Degrees Mobile Detector middleware to your Django settings. Inserting it just after "SessionMiddleware" is a safe place for it:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'fiftyone_degrees.mobile_detector.contrib.django.middleware.DetectorMiddleware',
)

Step 3:Configure the solution. When integrating 51Degrees Mobile Detector for Python with a Django website, there is an extra and more convenient option to set your preferences directly in your Django settings.

FIFTYONE_DEGREES_MOBILE_DETECTOR_SETTINGS = {
    'DETECTION_METHOD': 'lite-pattern-wrapper',
    'PROPERTIES': ('Id', 'IsMobile', 'WebWorkers', 'Html5'),
}

Step 4:The middleware provides some extra settings only available for Django users:

FIFTYONE_DEGREES_MOBILE_DETECTOR_SESSION_CACHE = True

If enabled, information about the detected device will be cached in the user's session.

FIFTYONE_DEGREES_MOBILE_DETECTOR_SESSION_FIELD = '_51degrees_device'

If session cache is set and the enabled, it allows configuring the caching key in the user's session. To see a demo of Django working with 51Degrees Python solution visit the blog.

Need Help?