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:
For trie matching:
Step 2: Add the 51Degrees Mobile Detector middleware to your Django settings. Inserting it just after "SessionMiddleware" is a safe place for it:
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.
Step 4: The middleware provides some extra settings only available for Django users:
If enabled, information about the detected device will be cached in the user's session.
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 .