Busy making things: @mc, notestinycast, github, links, photos.

Acknowledging the Mobile Web with Django

Posted: July 26th, 2006 | Author: | Filed under: Django, Mobile, Python | 11 Comments »

KTKA breaking news homepageI was reading up on HowToProvideAlternateViewsForMobileDevices on the Rails wiki this morning and couldn’t help but notice how much easier it is to set up a mobile version of a Django site. At World Online we have stripped-down barebones no frills “all we want are the facts ma’am” versions of all of our sites. They prove extremely useful during KU basketball games or when you’re in downtown lawrence and want to know what restaurants are open. Since our mobile sites are just alternate templates on the same views, setup goes something like this:

In main_site.settings:


In mobile_site.settings:

from main_site.settings import *

The first line imports all of the settings from your main site. We then overwrite the TEMPLATE_DIRS setting to point to the mobile version of our templates (and fall back to default templates if there isn’t a mobile specific version). Because every app that we write also gets a default template we can have a complete mobile site up and running by creating just one or two mobile base templates.

While Django can’t help you debate internally the “one web” versus “two webs” philosophies, it can definitely help you produce lightweight mobile-friendly content with minimum effort.

11 Comments on “Acknowledging the Mobile Web with Django”

  1. 1 Joseph Rose said at 10:03 am on July 26th, 2006:

    Wow! This sounds really simple!

    Does Django automatically detect when to use the mobile_site.settings file, or did you configure this somewhere else?

  2. 2 Matt Croydon said at 10:13 am on July 26th, 2006:


    We’ve done our best to promote our mobile sites on our “regular” by promoting mobile.sitename.com. Hopefully our users can expect to find a site there and it’s consistent across our different sites so that mobile.sitename.com is “guessable”.

    Automatically selecting which type of content to serve up based on device, browser, capabilities, etc is *really* hard to get right. If you’d like to go that route, you might want to check out WURFL which is about as good as it gets for detecting mobile device capabilities.

    I’d definitely suggest checking out Brian Fling’s mobile design slides from WebVisions 2006 which tackles all this mobile stuff quite well.

  3. 3 Joseph Rose said at 11:36 am on July 26th, 2006:

    So you guys have two installs of Django (one for each domain), or do you know which settings file to load based upon the url?

  4. 4 Jeremy Dunck said at 11:45 am on July 26th, 2006:

    (I don’t work for World, but do work with django in an environment doing the same thing.)

    It’s actually just one Django installation, but two different settings files.

    In apache’s vhost configuration, for the main site you do:
    SetEnv DJANGO_SETTINGS_MODULE main_site.settings

    and in the vhost for the mobile site, you do:
    SetEnv DJANGO_SETTINGS_MODULE mobile_site.settings


  5. 5 Joseph Rose said at 12:18 pm on July 26th, 2006:

    Thanks Jeremy!

  6. 6 Matt Croydon said at 12:47 pm on July 26th, 2006:

    Hey thanks for the clarification, Jeremy. Sometimes it’s dangerous to push the “post” button before caffeine.

  7. 7 Jakki Degg said at 12:38 pm on June 19th, 2007:

    Jakki Degg…

    I Googled for something completely different, but found your page…and have to say thanks. nice read….

  8. 8 BadB said at 7:49 pm on August 25th, 2009:

    Thanks Jeremy!

  9. 9 Lucy said at 6:27 pm on March 13th, 2010:

    And this is the main reason I love http://www.postneo.com. Stunning posts.


  10. 10 tory-burch-flip-flops said at 11:00 pm on February 14th, 2011:

    discount tory burch shoes…

    Tory Burch is developing faster and faster.Tory Burch Boots become more and more fashional.More and more people prefer to wear shoes like this.Tory Burch is an attainable, luxury, lifestyle brand defined by classic American sportswear with an eclectic …

  11. 11 reverse phone number lookup said at 12:40 am on February 17th, 2011:

    Just to let you know, this page seems a little bit funny from my smart phone. Who knows perhaps it’s just my mobile phone. Great post by the way.