wsgi.py ไม่ทำงานบน Ubuntu apache2 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

person user3461147    schedule 27.01.2015    source แหล่งที่มา


คำตอบ (1)


เป็นไปได้ไหมที่ซอร์สโค้ดของคุณขึ้นอยู่กับ 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.addsitedir และ Sentry(get_wsgi_application()) มาก่อน แต่ดูเหมือนทุกอย่างจะโอเค

person brsbilgic    schedule 27.01.2015