tags:

views:

61

answers:

1

After doing a bit of googling, I found these projects to help with serving static files:django-static with Nginx, and django-staticfiles.

Is there anybody that has had experience with one, or preferably both of these approaches, and that can recommend one or the other, or a 3rd?

+2  A: 

The usual way to handle static files is actually not sending them through django, but let the web server (e.g. apache or ngingx) handle them. I provide a small example for mod_wsgi, based on official django docs, found here.

Alias /media/ /usr/local/wsgi/static/media/

<Directory /usr/local/wsgi/static>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /usr/local/wsgi/scripts/django.wsgi

<Directory /usr/local/wsgi/scripts>
Order allow,deny
Allow from all
</Directory>

The first statement makes sure all files in /media will be served through apache directly, not django. The second statement is for setting up the django site itself. Now, using this media files do not go through django processing, which is often painfully slow.

The reason static file servers exist is mainly for development or very minimalistic rollouts.

KillianDS
For more information, see [the Django documentation page on serving static files](http://docs.djangoproject.com/en/dev/howto/static-files/). One thing I have seen recommended is to use an entirely different web server for static files, for example using lighttpd. This is why `MEDIA_ROOT` and `MEDIA_URL` assume no shared resource with the Django server, not even the server itself (and why the comments in the initial `settings.py` file show full URLs as examples).
Mike DeSimone
OK thanx. Starting to make sense now.
Jacques Bosch
Followup question: what is the point of those two static projects then?
Jacques Bosch
peterbe's project is actually about caching and compresssing and can be used together with this approach if I'm not mistaken. The other also provides helping functionality to collect file paths. This makes it easy to collect media files from several apps and put them together in one easy static folder. Again, you can use this together with this approach :).
KillianDS