3 tips for web designers using Django
In working with a good friend and web designer recently I came up with a few tips for web designers when working with Django -- things that might not be immediately apparent when reading the docs.
Keep it simple, read the documentation
There are often times when you have a goal for the user interface and you tend to over engineer how you go about implementing it. For the most part, Django makes things very straight forward. You'd be amazed at how many things can be accomplished with generic views and the template tags/filters. So if you've hit a spot where you think things are looking more complicated than they should be take a step back and peruse the documentation -- I bet you find a solution that is simple and clean.
Some resources:
- The official Django documentation
- The Django Book
- The #django channel on IRC
- The Django Wiki has a lot of good information. (Hint: View the title index.)
Reference the path to your media in your templates
This is an often asked question and recently Django added a media context processor to solve this. It's a good idea to point the media in your templates based on the MEDIA_URL setting in your settings.py file. This makes it trivial to move your static media around (from being served locally to Akamai or Amazon's S3 when your site gets dugg perhaps?). The built-in MEDIA_URL context processor was recently added to Django and will be available when Django version 0.97 comes out. Here's an example of usage:
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/style.css" media="screen">
Cross browser testing
Whether your developing and designing on a Mac or Windows or Linux, it's often desired to test your website on other platforms without publishing your site live. Here's a great tip to test your website in other browsers by serving up your project from your development machine using the built-in Django web server.
You typically running your server with the command:
./manage.py runserver
Start the built-in server with this command instead:
./manage.py runserver 0.0.0.0:8000
What this does is runs the server attaching to the IP address of your machine rather than 127.0.0.1. This allows you to go to another computer on your network and enter the IP address of your machine as the URL (eg: http://192.168.1.2:8000/) and pull up the site. This is great if you're developing on a Mac, say, and want to test in IE6 or IE7.
Serve static media locally
A bonus tip relating to the 3rd one (aka, I don't know how to count)! This page describes how to serve static media (CSS, images, etc.) using Django's built-in server for local development. This is also great for testing and works with the above tip.
That's all for now. Thanks for reading.
About this entry
Date Posted:
August 30th 2007 at 11:08:00 AM
Previous Entry:
Django Master Class at OSCON 2007
Next Entry:
Django Development Using git
Comments
blog comments powered by Disqus