wsgi.py 不适用于 ubuntu apache2 mod_wsgi



这是我的虚拟主机文件;

    Alias /static/ /home/ubuntu/app/boomset/static_root/
    <Directory /home/ubuntu/app/boomset/static_root>
            Require all granted
    </Directory>
    WSGIDaemonProcess boomset.com python-path=/home/ubuntu/app/boomset:/home/ubuntu/app/venv/lib/python2.7/site-packages
    WSGIProcessGroup boomset.com
    WSGIScriptAlias / /home/ubuntu/app/boomset/boomset/wsgi.py

    <Directory /home/ubuntu/app/boomset/boomset>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>

这是我 wsgi.py 文件;

"""
WSGI config for boomset project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
import sys
import site
sys.path.append('/home/ubuntu/app')
sys.path.append('/home/ubuntu/app/boomset')
sys.path.append('/home/ubuntu/app/boomset/boomset')
site.addsitedir('/home/ubuntu/app/venv/lib/python2.7/site-packages')
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "boomset.settings")
from django.core.wsgi import get_wsgi_application
application = Sentry(get_wsgi_application())

这是我的 Apache 错误日志文件。 REST 框架装饰器给出了一个错误,但这对我来说没有任何意义。我被卡住了!

[Tue Jan 27 03:42:17.382849 2015] [:error] [pid 2926:tid 140170072491776] [remote 64.79.151.225:16875]   File "/home/ubuntu/app/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 206, in __call__
[Tue Jan 27 03:42:17.382920 2015] [:error] [pid 2926:tid 140170072491776] [remote 64.79.151.225:16875]     response = self.get_response(request)
[Tue Jan 27 03:42:17.382933 2015] [:error] [pid 2926:tid 140170072491776] [remote 64.79.151.225:16875]   File "/home/ubuntu/app/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 196, in get_response
[Tue Jan 27 03:42:17.387153 2015] [:error] [pid 2926:tid 140170072491776] [remote 64.79.151.225:16875]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Tue Jan 27 03:42:17.387171 2015] [:error] [pid 2926:tid 140170072491776] [remote 64.79.151.225:16875]   File "/home/ubuntu/app/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 234, in handle_uncaught_exception

....

[Tue Jan 27 03:42:17.387714 2015] [:error] [pid 2926:tid 140170072491776] [remote 64.79.151.225:16875]     from rest_framework.decorators import action
[Tue Jan 27 03:42:17.387733 2015] [:error] [pid 2926:tid 140170072491776] [remote 64.79.151.225:16875] ImportError: cannot import name action

你的源代码是否可能依赖于 Django REST 2.x 但安装了 3.x 版本?因为action方法已从版本 3.x 中删除,这可能是导入错误的原因。您可以查看以下链接

https://github.com/tomchristie/django-rest-framework/blob/version-2.4.x/rest_framework/decorators.py

https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/decorators.py

我以前没有使用过site.addsitedirSentry(get_wsgi_application()),但一切似乎都很好。

最新更新