我'm writing a django site for internal use in my organization. I'm使用测试驱动的方法来开发this tutorial中的网站,因为我认为's good practice. I'm使用的是Ubuntu 12.04,以及来自存储库的apache服务器和mod_wsgi . 我的开发是在使用virtualenvwrapper创建的virtualenv中进行的 .

我希望在尽可能接近 生产环境 服务器的条件下测试网站,所以我以前从未做过 . 我已经阅读了mod_wsgidjango docs的相关位并观看了this video,它解决了我在文件权限方面遇到的问题 . 但我似乎陷入了最后的障碍,演示文稿并没有使用django 1.4并且它与早期版本有关但我'm not sure. I'm致力于使用本地apache服务器而不是django开发服务器,因为该站点需要搜索,我想要通过haystack和apache solr,我想在部署之前测试它并解决任何问题 .

我的wsgi.py文件只是股票django . 修剪文档字符串后,它看起来像这样:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fugit.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

我的httpd.conf看起来像这样:

WSGIScriptAlias / /var/www/djcode/fugit/fugit/fugit/apache/wsgi.py
WSGIPythonPath /var/www/djcode/fugit/fugit/fugit:/home/garry/.virtualenvs/fugit/lib/python2.7/site-packages


<Directory /var/www/djcode/fugit/fugit/fugit>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

当我访问localhost时,我收到以下错误 . 它看起来像PYTHONPATH问题,但我对django文档的理解是上面的httpd.conf中的第二行应该已经解决了这个问题 .

[Fri Dec 28 10:22:03 2012] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Fri Dec 28 10:22:03 2012] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Fri Dec 28 10:22:03 2012] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3280): Target WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py' cannot be loaded as Python module.
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3280): Exception occurred processing WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py'.
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1]   File "/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py", line 23, in <module>
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1]     from django.core.wsgi import get_wsgi_application
[Fri Dec 28 10:22:05 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.wsgi
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3279): Target WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py' cannot be loaded as Python module.
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3279): Exception occurred processing WSGI script '/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py'.
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1]   File "/var/www/djcode/fugit/fugit/fugit/apache/wsgi.py", line 23, in <module>
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1]     from django.core.wsgi import get_wsgi_application
[Fri Dec 28 10:22:08 2012] [error] [client 127.0.0.1] ImportError: No module named django.core.wsgi

谁能告诉我我在这里缺少什么?

编辑:

看起来我可能有一个virtualenvwrapper权限问题 . 我已经尝试按照this answer的建议移动我的virtualenvs,但现在virtualenvwrapper可以't seem to find itself. I'得到`[Errno 13]权限被拒绝' on trying to load initialization hooks. I' ve chmod 755新目录但没有骰子 .

进一步编辑:我通过使用nginx作为gunicorn的反向代理而不是使用Apache进行部署来解决这个问题 . 它在大约半小时内 Build 并顺利运行 .