简体   繁体   English

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

[英]500 Server Error on Django Website - ImportError: No module named django.core.wsgi

I am uploading a Django website to an Apache 2.4 server on Ubuntu 16.04. 我正在将Django网站上传到Ubuntu 16.04上的Apache 2.4服务器。 My server is running mod_wsgi. 我的服务器正在运行mod_wsgi。 I am getting an ImportError: No module named django.core.wsgi. 我收到一个ImportError:没有名为django.core.wsgi的模块。 I have read through many other solutions, but none seem to work. 我已经阅读了许多其他解决方案,但似乎没有一个可行。 I am thinking that my error has something to do with my Python installation (Python 2.7), but I am not sure. 我以为我的错误与我的Python安装(Python 2.7)有关,但我不确定。 My wsgi.py , server conf, and error messages from the Apache logs are below: 我的wsgi.py ,服务器conf和来自Apache日志的错误消息如下:

Apache Error Log: 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: 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: 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>

When I type which python to find where Python is installed, the result is /usr/bin/python 当我键入which python查找安装Python的位置时,结果为/usr/bin/python

When I try to visit my IP Address in the browser, I receive a 500 Server Error with the admin email provided in the Apache Conf, so I know this file is being used. 当我尝试在浏览器中访问我的IP地址时,在Apache Conf中提供的管理电子邮件中收到500服务器错误,因此我知道此文件正在使用中。

When I disable my wsgi.py file through my Apache Conf and visit my IP Address, there is a webpage for me to navigate the files I have in my /var/www/ folder. 当我通过Apache Conf禁用wsgi.py文件并访问我的IP地址时,会有一个网页供我浏览/var/www/文件夹中的文件。

When I test from django.core.wsgi import get_wsgi_application in the Python console, it works fine. 当我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 ,它工作正常。

I am not using virtualenv. 我没有使用virtualenv。

Is there any other way for me to debug this, or has anyone found a solution to this error? 我还有其他调试方法吗,还是有人找到了解决此错误的方法?

You need to edit your wsgi.py file to set the sys.path to include the parent directory that contains your novabucket module, probably like this: 您需要编辑wsgi.py文件以将sys.path设置为包括包含novabucket模块的父目录,可能是这样的:

import sys sys.path.insert(0, '/home/maxmackie/webapps/django/novabucket') More information is available in our documentation: Adding to sys.path within Python and WSGI Scripts import sys sys.path.insert(0,'/ home / maxmackie / webapps / django / novabucket')我们的文档中提供了更多信息:在Python和WSGI脚本中添加到sys.path

Be sure to restart your Apache after making these changes. 进行这些更改后,请确保重新启动Apache。 .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入错误:没有用于 wsgi 服务器设置的名为 django.core.wsgi 的模块 - ImportError: No module named django.core.wsgi for wsgi server setting ImportError:没有名为django.core.wsgi的模块 - ImportError: No module named django.core.wsgi “ ImportError:没有名为django.core.wsgi的模块” apache错误 - “ImportError: No module named django.core.wsgi” apache error WSGIDaemon进程语法错误-Mod_wsgi django ImportError:没有名为django.core.wsgi的模块 - WSGIDaemon Process syntax error - Mod_wsgi django ImportError: No module named django.core.wsgi Apache Django应用程序:ImportError:没有名为django.core.wsgi的模块 - Apache Django app: ImportError: No module named django.core.wsgi Django-ImportError:没有名为django.core.wsgi的模块 - Django - ImportError : no module named django.core.wsgi App Engine + Django:ImportError:没有名为django.core.wsgi的模块 - App Engine + Django: ImportError: No module named django.core.wsgi ImportError:使用nginx部署时,没有名为django.core.wsgi的模块 - ImportError: No module named django.core.wsgi when deploying with nginx ImportError:Elastic Beanstalk中没有名为django.core.wsgi的模块 - ImportError: No module named django.core.wsgi in Elastic Beanstalk 导入错误:没有名为 django.core.wsgi 的模块(ubuntu) - ImportError: No module named django.core.wsgi (ubuntu)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM