Mobilize your Django site
**Mobilize your Django site** This is the code for a Django middleware class to allow you to easily mobilize your Django site. It makes use of [Wapple.net](http://wapple.net)'s Web services to provide device profiling and markup generation. Using this middleware plugin, you can deliver your site to both mobile and web browsers using the same domain and exactly the same url structure and Python views. The WAPL markup language allows you to render sites to every single mobile device without worrying about the individual devices yourself. **Requirements** 1. The [SUDS](https://fedorahosted.org/suds/) Python SOAP client. 2. A WAPL dev key. Sign up for one at [http://wapl.info](http://wapl.info) 3. The Django sessions framework must be enabled. See [http://docs.djangoproject.com/en/dev/topics/http/sessions/](http://docs.djangoproject.com/en/dev/topics/http/sessions/) for how to install. **How To Use** 1. Save the code above as 'wapl_middleware.py' in the root of your project. 2. Replace 'YOUR-DEV-KEY-HERE' with your WAPL dev key. 3. In your project's 'settings'py', add the following to the bottom of your 'MIDDLEWARE_CLASSES' setting: `'myapp.wapl_middleware.WAPLMiddleware',` 4. For each line in your 'TEMPLATE_DIRS' setting, create a new folder under that folder called 'wapl' e.g. for 'myapp/templates/', you would create the folder under 'myapp/templates/wapl/'. 5. For each template used in your application, write a WAPL version and save it in the corresponding 'wapl' directory. See [http://wapl.info/docs/chapter/Developing-with-WAPL/](the WAPL docs) for information about the WAPL markup language. 6. Django template inheritance and includes can be used as normal, so I recommend creating a 'base.html' like this one. `<?xml version="1.0" encoding="UTF-8" ?> <wapl xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://wapl.wapple.net/wapl.xsd"> <head> {% block wapl_head %}{% endblock %} </head> <layout> {% block wapl_layout %}{% endblock %} </layout> </wapl>` 7. View your site from a mobile device, and you should see a nice mobile version. **How It Works** 1. When a request is made, the middleware checks to see if a session variable is held telling us if the device is mobile or not. 2. If we don't already know, it calls the WAPL web services to check. It then stores this in the session for subsequent requests. 3. If the device is a mobile device, it appends 'wapl' to each line in your 'TEMPLATE_DIRS' setting. Your view code will work exactly the same as normal, and the 'wapl' templates will be used whenever a response is rendered. 4. When a response is about to be rendered, the middleware checks to see if the device is a mobile one. 5. If it is mobile, and the response about to be sent has a status code of 200 (OK), it sends the WAPL markup to the WAPL web service to generate the correct markup for that device. 6. Otherwise, it outputs the response unmodified. **Tips** 1. Don't try to migrate your whole site to mobile - design for mobile and consider the user's goals on a handset. 2. If leaving sections out, don't just leave the wapl view out. Include one that says 'This page is not available on mobile'. This will make sure none of your external links are dead on the mobile version. 3. For full developer reference, information and schemas, see [http://wapl.info](WAPL.info).
- mobile
- web-services
- mobilize