问题描述
我把我的Django的网站在生产中的第一次,所以请原谅我的无知。
I'm putting my django site in production for the first time so please forgive for my ignorance.
我试图把我的Django的网站上的Apache。我读过有关mod_wsgi的文档和尝试,简单的Hello World所以它被配置确定。我在这个问题似乎是用virtualenvs它。我想设置的东西,包括正确和virtualenvs一切都那么我已经准备好为未来的网站。
I'm trying to put my django site on apache. I've read documentation about mod_wsgi and tried that simple Hello world so it is configured OK. The problem I'm having seems to be with using virtualenvs with it. I wanna set things up properly including virtualenvs and everything so I'm ready for future sites.
要现在的问题。
我得到在Apache日志的错误是:
The error I'm getting in apache log is:
No module named django.core.handlers.wsgi
如此看来,它不能正常读我的virtualenvs。
So it seems that it is not reading my virtualenvs properly.
这是我的WSGI脚本:
This is my wsgi script:
import os
import sys
import site
site.addsitedir('/home/user/.virtualenvs/myapp/lib/python2.7/site-packages')
path = '/home/user/django/myapp/myapp'
if path not in sys.path:
sys.path.append(path)
sys.stdout = sys.stderr
print sys.path
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
这是Apache的错误日志。我打印出来的sys.path所以你可以看到它的样子。
And this is the error log from apache. I printed out the sys.path so you can see what it looks like.
[Tue Jun 05 14:54:07 2012] [error] ['/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages/PIL', '/usr/lib/python2.7/site-packages/setuptools-0.6c11.egg-info', '/home/user/.virtualenvs/myapp/lib/python2.7/site-packages', '/home/user/django/myapp/myapp']
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] mod_wsgi (pid=1039): Target WSGI script '/srv/http/wsgi_scripts/myapp.wsgi' cannot be loaded as Python module.
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] mod_wsgi (pid=1039): Exception occurred processing WSGI script '/srv/http/wsgi_scripts/myapp.wsgi'.
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] File "/srv/http/wsgi_scripts/myapp.wsgi", line 17, in <module>
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Tue Jun 05 14:54:07 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi
如果您有任何建议或已经有类似的问题,请帮助。
If you have any suggestions or already had similar issue please help.
感谢
推荐答案
对于任何像我一样,可能有类似的问题。你需要检查整个路径权限登录到您的virtualenv的存储目录。
For anyone that might have similar problem as I did. You need to check the whole path privileges to the directory where your virtualenv is stored.
我检查了主目录,并修改的权限,但是忘了改权限到我的用户目录和固定的东西。
I checked the home directory and changed privileges, but forgot to change privileges to my user directory and that fixed the thing.
希望这有助于。
这篇关于设置在Apache Django的(mod_wsgi的,virtualenv中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!