virtualenv 上的 django+mod_wsgi 不起作用
我刚刚在 virtualenv 上完成了 django 应用程序的设置,使用 Fabric 脚本部署顺利,但现在 .wsgi 不起作用,我尝试了互联网上的所有变体,但没有运气。我的 .wsgi 文件是:
import os
import sys
import django.core.handlers.wsgi
# put the Django project on sys.path
root_path = os.path.abspath(os.path.dirname(__file__) + '../')
sys.path.insert(0, os.path.join(root_path, 'kcdf'))
sys.path.insert(0, root_path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'kcdf.settings'
application = django.core.handlers.wsgi.WSGIHandler()
我不断收到相同的错误:
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] mod_wsgi (pid=16938): Exception occurred processing WSGI script '/home/kcdfweb/webapps/kcdf.web/releases/current/kcdf/apache/kcdf.wsgi'.
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] Traceback (most recent call last):
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 230, in __call__
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] self.load_middleware()
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 33, in load_middleware
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 269, in __getattr__
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] self._setup()
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 40, in _setup
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] self._wrapped = Settings(settings_module)
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 75, in __init__
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] ImportError: Could not import settings 'kcdf.settings' (Is it on sys.path? Does it have syntax errors?): No module named kcdf.settings
我的虚拟环境位于 /home/user/webapps/kcdfweb 我的应用程序是 /home/user/webapps/kcdf.web/releases/current/project_name 我的 wsgi 文件 home/user/webapps/kcdf.web/releases/current/project_name/apache/project_name.wsgi
I've just finished setting up a django app on virtualenv, deployment went smoothly using a fabric script, but now the .wsgi is not working, I've tried every variation on the internet but no luck. My .wsgi file is:
import os
import sys
import django.core.handlers.wsgi
# put the Django project on sys.path
root_path = os.path.abspath(os.path.dirname(__file__) + '../')
sys.path.insert(0, os.path.join(root_path, 'kcdf'))
sys.path.insert(0, root_path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'kcdf.settings'
application = django.core.handlers.wsgi.WSGIHandler()
I keep getting the same error:
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] mod_wsgi (pid=16938): Exception occurred processing WSGI script '/home/kcdfweb/webapps/kcdf.web/releases/current/kcdf/apache/kcdf.wsgi'.
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] Traceback (most recent call last):
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 230, in __call__
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] self.load_middleware()
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 33, in load_middleware
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 269, in __getattr__
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] self._setup()
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 40, in _setup
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] self._wrapped = Settings(settings_module)
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 75, in __init__
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
[Sun Apr 18 12:44:30 2010] [error] [client 41.215.123.159] ImportError: Could not import settings 'kcdf.settings' (Is it on sys.path? Does it have syntax errors?): No module named kcdf.settings
my virtual environment is on /home/user/webapps/kcdfweb
my app is /home/user/webapps/kcdf.web/releases/current/project_name
my wsgi file home/user/webapps/kcdf.web/releases/current/project_name/apache/project_name.wsgi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议您查看文档,了解如何将 Virtualenv 与 mod_wsgi 结合使用。他们提供了一些连接虚拟环境的替代方法,这可能更适合您。
I'd recommend that you look at the docs for using Virtualenv with mod_wsgi. They offer a few alternative approaches for hooking into your virtualenv which might work better for you.
您需要添加距 wsgi 文件向上两个目录,因此
您应该添加
...,因为您的 wsgi 文件位于项目文件夹下名为
apache
的目录中。You need to add the directory that is two up from your wsgi file, so instead of:
you should have
...as your wsgi file is in a directory called
apache
, under your project folder.如果您使用的是 virtualenv,则需要在 WSGI 脚本中激活它以正确设置路径。
If you're using a virtualenv, you'll need to activate it within the WSGI script to set the paths up correctly.
您的“kcdf”目录中有
__init__.py
文件吗?如果没有它,您的设置文件将无法导入。另外,如果您希望能够从 virtualenv 导入内容,您应该在 virtualenv 的 site-packages 目录上调用 site.addsitedir() 。有关详细信息,请参阅mod_wsgi 文档。虽然如果它甚至无法导入您的设置,我认为这不是您当前的问题。
Do you have an
__init__.py
file in your "kcdf" directory? Without that your settings file cannot be imported.Also, you should be calling site.addsitedir() on the virtualenv's site-packages directory, if you expect to be able to import stuff from the virtualenv. See the mod_wsgi docs for details. Though if it can't even import your settings, I don't think this is your current problem.