管理Django静态文件:使用django-static还是django-staticfiles? [英] Managing Django static files: with django-static or django-staticfiles?

查看:63
本文介绍了管理Django静态文件:使用django-static还是django-staticfiles?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进行了一些谷歌搜索之后,我发现这些项目可以帮助提供静态文件: django-static Nginx ,以及 django-staticfiles .

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?

推荐答案

处理静态文件的通常方法实际上不是通过django发送它们,而是让Web服务器(例如apache或ngingx)对其进行处理.我提供了一个基于django官方文档的mod_wsgi的小示例,该文档位于

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>

第一个语句确保/media中的所有文件都将通过apache直接提供,而不是django.第二条语句用于设置django网站本身.现在,使用此媒体文件无需进行django处理,这通常会非常缓慢.

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.

这篇关于管理Django静态文件:使用django-static还是django-staticfiles?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆