Proxying the Django Development Server
2008-04-03 05:44:14-0400 - development (4),setup (1),django (1) - 2 comments
Let’s face it: the development server that comes with Django rocks. It’s nice that it just works. There’s no restarting of code necessary, no need to run another process, nothing.
There is one drawback though: speed. It’s horrendously slow whenever you need to develop a site that has a good quantity of media on it. There are two solutions to this:
- Serve your media somewhere else and use a MEDIA_URL that points to another server.
- Proxy your code server through another web server.
Not everyone can easily set up the first option, so I will talk about the second option right now. The first choice is to choose an appropriate web server to serve the static media. Enter lighttpd.
Lighttpd Configuration
Lighttpd is a very fast and lightweight web server for serving static content. Installation varies depending on what operating system you’re using. If you’re using Ubuntu, you can just enter:
$ sudo apt-get install lighttpd
and it will install. It turns out that setting it up is not all that hard either. First, choose a directory you want to contain all your media. For this entry, I’ll call it /media. Once you do this, you can use the following lighttpd configuration:
$HTTP["URL"] !~ "^/media" {
proxy.server = ( "" =>
( (
"host" => "127.0.0.1",
"port" => 8080
) )
)
}
Then run your development server as normal:
$ ./manage.py runserver 8080
and when you go to http://localhost/ you should be able to test your application with both the speed of serving fast media and the convenience of code restarts.






Comments on This Post:
Posted by Frank Malina
on Aug. 22, 2008
This is a cool tip, the slow development server was a real pain. I installed Lighty on localhost port:80, as you suggested and changed settings to:
MEDIA_URL = 'http://localhost/static/' MEDIA_ROOT = '/home/user1/projects/project/static/' ADMIN_MEDIA_PREFIX = 'http://localhost/media/'I also had to push Apache to another port to make it work and change the Lighty document root folder in the config to my project folder.
Now its lightning fast.
As I did it, I realized that my old Apache would be just good for the job. It's not Lightly that is making it fast. As I understand it, It's just that that serving static files is taking the resources of the development server, that could be used to serve Django generated HTML.
Frank, Django development Manchester
Reply To This Comment
Posted by Franco Cedillo
on Feb. 24, 2009
Reply To This Comment