I 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
:
TEMPLATE_DIRS = (
'/path/to/templates/mainsite.com/',
'/path/to/templates/default/',
)
In mobile_site.settings
:
from main_site.settings import *
TEMPLATE_DIRS = (
'/path/to/templates/mobile.mainsite.com/',
'/path/to/templates/default/'
)
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.
Comments
11 responses to “Acknowledging the Mobile Web with Django”
Wow! This sounds really simple!
Does Django automatically detect when to use the mobile_site.settings file, or did you configure this somewhere else?
Joseph,
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.
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?
(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
Tada!
Thanks Jeremy!
Hey thanks for the clarification, Jeremy. Sometimes it’s dangerous to push the “post” button before caffeine.
Jakki Degg…
I Googled for something completely different, but found your page…and have to say thanks. nice read….
Thanks Jeremy!
And this is the main reason I love http://www.postneo.com. Stunning posts.
http://pecuniaryvideos.blogspot.com/
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 …
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.