![](/img/trans.png)
[英]ImportError: No module named django.core.wsgi for wsgi server setting
[英]500 Server Error on Django Website - ImportError: No module named django.core.wsgi
我正在將Django網站上傳到Ubuntu 16.04上的Apache 2.4服務器。 我的服務器正在運行mod_wsgi。 我收到一個ImportError:沒有名為django.core.wsgi的模塊。 我已經閱讀了許多其他解決方案,但似乎沒有一個可行。 我以為我的錯誤與我的Python安裝(Python 2.7)有關,但我不確定。 我的wsgi.py
,服務器conf和來自Apache日志的錯誤消息如下:
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 admin@site.com
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地址時,在Apache Conf中提供的管理電子郵件中收到500服務器錯誤,因此我知道此文件正在使用中。
當我通過Apache Conf禁用wsgi.py
文件並訪問我的IP地址時,會有一個網頁供我瀏覽/var/www/
文件夾中的文件。
當我from django.core.wsgi import get_wsgi_application
測試時from django.core.wsgi import get_wsgi_application
在Python控制台中from django.core.wsgi import get_wsgi_application
,它工作正常。
我沒有使用virtualenv。
我還有其他調試方法嗎,還是有人找到了解決此錯誤的方法?
您需要編輯wsgi.py文件以將sys.path設置為包括包含novabucket模塊的父目錄,可能是這樣的:
import sys sys.path.insert(0,'/ home / maxmackie / webapps / django / novabucket')我們的文檔中提供了更多信息:在Python和WSGI腳本中添加到sys.path
進行這些更改后,請確保重新啟動Apache。 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.