Django
The Python API includes Django middleware together with an example of how to deploy it. To start with you will need to install Django, if you haven't already:
$ sudo pip install django
If you installed the 51Degrees Python API through pip, you will need to download the source from GitHub as this includes the Django example page. Within the "Device-Detection" folder, go to "python/core/django-example" in a terminal. Then to see it in action, all you need to do is run:
$ python manage.py runserver
This will start a server at port 8000 of the localhost. Navigating to "localhost:8000" in your browser will give you a simple page showing various properties of the device you are using, as identified by the match. Below is an example of how this will look.
The example site uses an empty Django server and adds the 51Degrees Python middleware in the settings file as below.
MIDDLEWARE_CLASSES = ( ... 'fiftyone_degrees.mobile_detector.contrib.django.middleware.DetectorMiddleware', ) ... TEMPLATE_CONTEXT_PROCESSORS = ( ... 'fiftyone_degrees.mobile_detector.contrib.django.context_processors.device', )
The page that is served contains calls to middleware functions to access properties from the detector. Properties for the device can be fetched as follows:
Detection Method: {{ device.method }} Matched Properties {% for name, value in device.properties.items %} {{ name }}: {{ value }} {% endfor %}