wsgi.py不适用于ubuntu apache2 mod_wsgi

时间:2015-01-27 03:45:43

标签: python django ubuntu mod-wsgi

这是我的VirtualHost文件;

    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错误日志文件。休息框架装饰器给出了一个错误,但它对我没有任何意义。我被困了!

[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

1 个答案:

答案 0 :(得分:0)

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

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()),但一切似乎都没问题。