Build a Mobile and Desktop-Friendly Application in Django in 15 Minutes

This article quickly walks you through the process of setting up an absolutely minimal mobile- and desktop-friendly web application using the Django framework. This particular framework works very well with mobile thanks to the way its templates are structured and makes for a good choice for new web-based applications. This article assumes that you have python 2.3 or later and SVN already installed and working.

First we need to download the latest Django:

~$ wget
~$ tar xzvf Django-1.0.2-final.tar.gz
~$ cd Django-1.0.2-final
~$ sudo python install

Install sqlite (often not included in Linux distributions):

~$ sudo apt-get install python-sqlite

Create a new project:

~$ startproject mobapp

( should now be in path). This should give you a directory structure like the following:


Edit to use sqlite, and pick a db name

Sqlite is probably the easiest way to get started but if you want to use MySQL instead it requires just the addition of the DB name and authentication credentials to work. Now you need to write the relevant initial data into the DB (this is the data the Django uses for the Administration interface):

~$ cd mobapp
~/mobapp$ ./ syncdb

You will be asked if you want to create a superuser. This is recommended (to get all the cool Django DB admin stuff). Right now the application is ready to run, but does absolutely nothing. Remedy this by typing the following:

~/mobapp$ ./ startapp pub

This command creates a new "app" within the project. This should create a new directory called pub with some files in it, something like this:


Now open up the and edit it to make it aware of the new app:

Now to develop the actual app. For the sake of simplicity we’ll leave the alone for now — this application will not use any database functionality.

Edit pub/ — this is where the guts of the code will reside. Paste in the following code:

This code requires 2 templates, one for mobile users, the other for desktop users. We need to create these templates and put them in a directory that Django knows about.

~/mobapp$ mkdir pub/templates

Create two new files in this directory, called m_index.html and index.html. You can put the following content in these files:



Now we need to let Django know where the templates for the project are. Open and add a line pointing to the relevant directory e.g.

Now that our index method is ready in, we need to point a URL at it. Add the following line to

This pattern tells Django to point any blank URL at the index method in e.g.

And that’s it. Now if you start the server you have a minimal mobile- and desktop-friendly app:

~/mobapp$ ./ runserver
Validating models...
0 errors found
Django version 1.0.2 final, using settings 'mobapp.settings'
Development server is running at
Quit the server with CONTROL-C.

If you now go to http://localhost:8000/ with your browser you should see the following page:

desktop view

Visit the same URL with a mobile device and you will see something like this:

mobile view


This is an absolutely minimal Django application with a very modest feature set. Its main purpose is to demonstrate an approach to building a Django application that can simultaneously serve mobile and desktop users rather than show off any of Django’s great features. Please note that the device detection method used in this article is very basic, and really serves only as a way to differentiate mobile from desktop users rather than as a way to fine-tune the experience to the end device. To build a really consumer-friendly application you should use a more sophisticated device detection technology such as DeviceAtlas, which works fine with Django. Note that the device detection code used in this example is modelled on Andy Moore‘s PHP code.

This code for this application can be downloaded from the link below (

Exclusive tips, how-tos, news and comment

Receive monthly updates on the world of mobile dev.

Other Products

Market leading device intelligence for the web, app and MNO ecosystems
DeviceAtlas - Device Intelligence

Real-time identification of fraudulent and misrepresented traffic
DeviceAssure - Device Verification

A free tool for developers, designers and marketers to test website performance
mobiReady - Evaluate your websites’ mobile readiness

© 2024 DeviceAtlas Limited. All rights reserved.

This is a website of DeviceAtlas Limited, a private company limited by shares, incorporated and registered in the Republic of Ireland with registered number 398040 and registered office at 6th Floor, 2 Grand Canal Square, Dublin 2, Ireland