Django Sites for Pixel-Challenged Displays

If you have a website, you are inherently going to be judged on your aesthetics of publishing at some point whether you like it or not. Most people flock to well presented content - even if it's garbage - over time. The situation is futher complicated when you realize that the landscape of digital content is changing rapidly. The traditional desktop computing experience continues to evaporate. The proliferation of portable web-enabled devices suggests that people will consume more content away from the traditional desktop-in-the-back-room scenario. The upside is that the casual consumer may feel more obliged to participate in this new medium. From the perspective of content providers, this means increased pressure to ensure that your content delivery experience is satisfying across an increasingly dizzying array of presentation modes.

Nathan Borror of Playground Blues recently decided to make his website available for mobile devices. He sat down in a local cafe and a few hours later his site was rockin' for mobile devices. Nathan's article and Jeff's comment highlight one the inherent strengths of the Django platform - it was created for journalists and thus has a lot of nice facilities for any type of publishing application.

The fact that one can take an existing site and modify the content output format without really needing to actually modify any of the site executable code is pretty slick from a maintenance perspective. The process he describes is:

  1. Make a copy of your local settings (let's say "mobile settings")
  2. Add templates suited to mobile presentation and add the template directories to your mobile settings file ahead of the existing site template directories. This way, Django will look in the mobile templates first for an appropriate template.

The result is that incoming requests for which you've provided mobile-specific templates for get rendered back in a mobile-friendly format. If none exists, you naturally fallback to your regular site templates.

The beauty of this technique is that you can think about supporting any number of output formats as long as you can express the proper syntax with the combination of the context data. This isn't the only way one can return different output formats using Django. Views, middleware, and (indirectly) serializers can all affect the output format; each with trade-offs. Nathan has documented a method that is not immediately obvious but is both elegant and very powerful. Thanks Nathan!

About this entry

Content Category:
News
Topics:
content format  django  mobile  nathan borror  playground blues  
 

<<     Back to Unbracketed Home Post a Comment Now

Post a comment

Your name:

Comment:

  1. Markdown syntax is allowed. HTML tags will be stripped.
  2. CodeHilite NOT supported at this time but coming soon...
  3. Constructive statements and good attitudes are encouraged - being kind is better than being right
Clicky Web Analytics