在部署django应用程序时,应该在Apache中设置DJANGO_SETTINGS_MODULE?

我正在部署一个Django的应用程序,但我似乎无法看到在Apacheconfiguration正确的设置。 我把我的django应用程序放在/path/to/mysite.com/teabag/current/

DirectoryIndex index.html DocumentRoot /path/to/mysite.com/teabag/current/ <Location "/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE settings_production PythonPath "['/path/to/mysite.com/teabag/current'] + sys.path" PythonDebug On </Location> <Location "/media/"> SetHandler None </Location> <LocationMatch "\.(jpg|gif|png)$"> SetHandler None </LocationMatch> 

但它给了我这个错误:

 ImportError: Could not import settings 'settings_production' (Is it on sys.path? Does it have syntax errors?): No module named settings_production 

我有一个怀疑,我的Pythonpath是不正确的。 它应该在/path/to/mysite.com/teabag?上面一级,因此设置应该是“current.settings_production”

我有点卡住,任何帮助将不胜感激,谢谢。

您用于PythonPath的值应包括要在应用程序中导入的所有模块的父目录。 它还应该包含DJANGO_SETTINGS_MODULE位置的父目录。

我猜猜会是:

 SetEnv DJANGO_SETTINGS_MODULE current.settings_production PythonPath "['/path/to/mysite.com/teabag/'] + sys.path" 

我同意你的问题的答案rkthkr,但我注意到了这一点。

 DocumentRoot /path/to/mysite.com/teabag/current/ 

这不会导致安全问题? 这将让某人访问您的应用程序代码。 应该不需要将DocumentRoot指向您的应用程序目录。 所有的静态媒体应该从一个单独的目录中提供。 如果您在Linux系统上,则可以将媒体从应用程序目录符号链接到DocumentRoot目录。