开发者

Managing Django static files: with django-static or django-staticfiles?

After doi开发者_运维百科ng 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜