我在Ubuntu 16.04上將Django網站上傳到Apache 2.4服務器。我的服務器正在運行mod_wsgi。我得到一個名爲django.core.wsgi的ImportError:No模塊。我已經閱讀了許多其他解決方案,但似乎沒有任何工作。我在想我的錯誤與我的Python安裝(Python 2.7)有關,但我不確定。我wsgi.py
,服務器的conf和錯誤從Apache日誌信息如下:Django網站上的500服務器錯誤 - ImportError:沒有名爲django.core.wsgi的模塊
Apache的錯誤日誌:
[Thu Apr 13 15:51:06.891778 2017] [authz_core:debug] [pid 27832:tid 140404955539200] mod_authz_core.c(809): [client 134.53.122.114:63670] AH01626: authorization result of Require all granted: granted, referer: http://173.255.204.6/
[Thu Apr 13 15:51:06.891833 2017] [authz_core:debug] [pid 27832:tid 140404955539200] mod_authz_core.c(809): [client 134.53.122.114:63670] AH01626: authorization result of <RequireAny>: granted, referer: http://173.255.204.6/
[Thu Apr 13 15:51:06.891884 2017] [authz_core:debug] [pid 27832:tid 140404955539200] mod_authz_core.c(809): [client 134.53.122.114:63670] AH01626: authorization result of Require all granted: granted, referer: http://173.255.204.6/
[Thu Apr 13 15:51:06.891891 2017] [authz_core:debug] [pid 27832:tid 140404955539200] mod_authz_core.c(809): [client 134.53.122.114:63670] AH01626: authorization result of <RequireAny>: granted, referer: http://173.255.204.6/
[Thu Apr 13 15:51:06.892105 2017] [wsgi:info] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] mod_wsgi (pid=27831, process='site', application='site.com|'): Loading WSGI script '/var/www/site/site/wsgi.py'.
[Thu Apr 13 15:51:06.892490 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] mod_wsgi (pid=27831): Target WSGI script '/var/www/site/site/wsgi.py' cannot be loaded as Python module.
[Thu Apr 13 15:51:06.892504 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] mod_wsgi (pid=27831): Exception occurred processing WSGI script '/var/www/site/site/wsgi.py'.
[Thu Apr 13 15:51:06.892532 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] Traceback (most recent call last):
[Thu Apr 13 15:51:06.892564 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] File "/var/www/site/site/wsgi.py", line 9, in <module>
[Thu Apr 13 15:51:06.892611 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] from django.core.wsgi import get_wsgi_application
[Thu Apr 13 15:51:06.892647 2017] [wsgi:error] [pid 27831:tid 140404925069056] [remote 134.53.122.114:11921] ImportError: No module named django.core.wsgi
wsgy.py:
import os, sys
sys.path.append('/var/www/site')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "site.settings")
application = get_wsgi_application()
的Apache的conf:
<VirtualHost *:80>
ServerName site.com
ServerAlias www.site.com
ServerAdmin [email protected]
DocumentRoot /var/www/site
WSGIDaemonProcess site python-path=/usr/bin/python
WSGIProcessGroup site
WSGIScriptAlias//var/www/site/site/wsgi.py process-group=site
<Directory /var/www/site/site>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /media/ /var/www/site/media/
Alias /static/ /var/www/site/static/
<Directory /var/www/site/static>
Require all granted
</Directory>
<Directory /var/www/site/media>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
當我輸入which python
來查找Python的安裝位置時,結果爲/usr/bin/python
當我嘗試在瀏覽器中訪問我的IP地址時,我收到了500個服務器錯誤,並在Apache Conf中提供了管理員電子郵件,因此我知道正在使用此文件。
當我通過我的Apache Conf禁用我的wsgi.py
文件並訪問我的IP地址時,有一個網頁可供我瀏覽我在/var/www/
文件夾中的文件。
當我在Python控制檯中測試from django.core.wsgi import get_wsgi_application
時,它工作正常。
我沒有使用virtualenv。
有沒有其他的方法可以讓我調試這個,或者有人找到了解決這個錯誤的方法?
@Thameem當我在錯誤日誌中使用相同的輸出時,仍然出現服務器錯誤。 – Kevin
WSGIDaemonProcess網站中的python-PATH =的/ usr/bin中/ Python的 嘗試什麼,而不是這個 WSGIDaemonProcess網站中的python-PATH = /無功/網絡/網站/網站蟒蛇回家=的/ usr/bin中/ Python的 – Thameem
@Thameem我嘗試過這些並收到相同的錯誤。你知道是否有任何方法可以得到更詳細的錯誤信息? – Kevin