繁体   English   中英

Django网站上的500服务器错误-ImportError:没有名为django.core.wsgi的模块

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM