使用mod_wsgi和Django提供静态文件 [英] Serving static files with mod_wsgi and Django

查看:104
本文介绍了使用mod_wsgi和Django提供静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用mod_python的django应用程序,这是一种非常典型的配置,除了媒体文件由文档根目录中的(我知道,不建议使用)"media"目录提供服务.我想测试一下,也许要用mod_wsgi进行部署,但是我不知道如何创建一些简单的服务静态文件的方法. mod_python允许使用Apache指令,例如:

I have a django application using mod_python, fairly typical configuration except that media files are being served by a (I know, not recommended) 'media' directory in the document root. I would like to test and maybe deploy with mod_wsgi but I cannot figure out how to create something simple to serve static files. mod_python allows the use of Apache directives like:

<Location '/'>
    SetHandler MyApplication.xyz.....
</Location>

<Location '/media'>
    SetHandler None
</Location>

django文档似乎指向上面的第二个块,这是对mod_wsgi进行类似异常的正确方法,但是在我的测试中,root以下的所有内容仍被发送到wsgi应用程序.有什么好方法可以使用mod_wsgi设置静态媒体目录,还是由于令人信服的技术原因而故意不支持我做的事情?欢迎提供指向完全不同方法的答案.

The django docs seem to point to the second block above as the correct way to make a similar exception for mod_wsgi, but in my tests everything below root is still being sent to the wsgi app. Is there a good way set a static media directory with mod_wsgi, or is what I am trying to do intentionally unsupported for compelling technical reasons? Answers that point to entirely different approaches are welcome.

推荐答案

mod_wsgi文档介绍了如何设置静态文件,该文件显示在安装WSGI应用程序的URL下方的URL上.参见:

The mod_wsgi documentation explains how to setup static files which appear at a URL underneath that which the WSGI application is mounted at. See:

http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Hosting_Of_Static_Files

请注意,使用WSGIScriptAlias指令挂载WSGI应用程序时,不需要'Options + ExecCGI'.仅当使用AddHandler将应用程序挂载为资源时,才需要"ExecCGI"选项.

Note that 'Options +ExecCGI' is not need when using WSGIScriptAlias directive to mount the WSGI application. The 'ExecCGI' option is only required when using AddHandler to mount applications as resources.

这篇关于使用mod_wsgi和Django提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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