我在Apache上设置了mode_wsgi并且工作正常但是当我尝试在其上部署Django时,我得到500内部服务器错误。以下是我从Apache错误日志中获取的跟踪
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] mod_wsgi (pid=8212): Target WSGI script 'H:/DEV/python/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] mod_wsgi (pid=8212): Exception occurred processing WSGI script 'H:/DEV/python/mysite/mysite/wsgi.py'.
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] File "H:/DEV/python/mysite/mysite/wsgi.py", line 13, in <module>
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] from django.core.wsgi import get_wsgi_application
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\wsgi.py", line 1, in <module>
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] from django.core.handlers.wsgi import WSGIHandler
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 11, in <module>
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] from django.core.handlers import base
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 12, in <module>
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] from django.db import connections, transaction
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\db\\__init__.py", line 83, in <module>
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] signals.request_started.connect(reset_queries)
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\dispatch\\dispatcher.py", line 88, in connect
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] if settings.DEBUG:
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\conf\\__init__.py", line 54, in __getattr__
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] self._setup(name)
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\conf\\__init__.py", line 49, in _setup
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] self._wrapped = Settings(settings_module)
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\conf\\__init__.py", line 132, in __init__
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] % (self.SETTINGS_MODULE, e)
[Thu Nov 28 12:14:40 2013] [error] [client 127.0.0.1] ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named mysite.settings
对此的任何帮助将不胜感激。感谢
以下是网站的apache conf
WSGIScriptAlias / "H:/DEV/python/mysite/mysite/wsgi.py"
WSGIPythonPath "H:/DEV/python/mysite:C:/Python27/Lib/site-packages"
<Directory "H:/DEV/python/mysite">
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
这是wsgi文件中的代码
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
答案 0 :(得分:1)
将此添加到wsgi脚本:
import sys
sys.path.append('H:/DEV/python/mysite')
将它放在os.environ部分
之前答案 1 :(得分:1)
我想我终于在搜索后找到了真正的问题:
apache配置中的 WSGIPythonPath
指令是错误的,您需要在:
之后更改;
,因为您在Windows上,所以它必须如下所示:
WSGIPythonPath "H:/DEV/python/mysite;C:/Python27/Lib/site-packages"
这就是为什么你的wsgi没有找到你的网站设置,这是处理这个问题的正确方法。使用此修复程序,您无需修改自动生成的wsgi文件以在sys.path中添加您的站点(在他的答案中为suggeted @yuvi),因为它是多余的(添加sys.path是{{1} })而不是最佳实践。
(更多关于wsgi docs)
你也应该改变这个:
WSGIPythonPath
由:
<Directory "H:/DEV/python/mysite">
答案 2 :(得分:0)
我刚遇到同样的问题。编辑apache conf文件'http.conf'并将您的站点packapge路径添加到WSGIPythonPath可能会有所帮助。如下:
for (int i = 0; i < 5; i++) {
// find out whether this element was already assigned a specific value
if (array[i] == ??? )
{
// the element has yet to be assigned
}
}
查看有关django docs
的更多详情特别是,Windows上的目录名称之间的路径分隔符为 WSGIPythonPath "c:/Users/mysite;c:/Users/yoursite"
,而不是UNIX系统上的;
。