gpt4 book ai didi

django - 无法将目标WSGI脚本'/var/www/backend/backend/wsgi.py'加载为Python模块

转载 作者:行者123 更新时间:2023-12-02 04:25:05 30 4
gpt4 key购买 nike

我正在ubuntu服务器上部署Django Web应用程序。配置已设置。但是,以某种方式,它显示了500 Internal Server Error。我检查了apache错误日志,发现以下错误条目:

[Tue Mar 26 08:50:56.540300 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] mod_wsgi (pid=18832): Target WSGI script '/var/www/backend/backend/wsgi.py' cannot be loaded as Python module.
[Tue Mar 26 08:50:56.540376 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] mod_wsgi (pid=18832): Exception occurred processing WSGI script '/var/www/backend/backend/wsgi.py'.
[Tue Mar 26 08:50:56.540498 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] Traceback (most recent call last):
[Tue Mar 26 08:50:56.540542 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] File "/var/www/backend/backend/wsgi.py", line 12, in <module>
[Tue Mar 26 08:50:56.540553 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] from django.core.wsgi import get_wsgi_application
[Tue Mar 26 08:50:56.540584 2019] [wsgi:error] [pid 18832] [remote 27.61.32.236:42365] ImportError: No module named 'django'

我已经尝试了针对stackoverflow上发现的相同错误的解决方案。这些配置上还缺少什么吗?

Apache配置
Listen 8000
<VirtualHost *:8000>
WSGIDaemonProcess backendapp python-home=/var/www/backend/venv python-path=/var/www/backend
WSGIProcessGroup backendapp
WSGIPassAuthorization On
WSGIScriptAlias / /var/www/backend/backend/wsgi.py
ErrorLog /var/www/backend/error.log
CustomLog /var/www/backend/access.log combined
</VirtualHost>

wsgi.py
import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")

application = get_wsgi_application()

使用python 3.6和mod_wsgi在服务器上启用。

最佳答案

问题是wsgi python版本不匹配。我使用的是python 3,因此:

$ sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py3

关于django - 无法将目标WSGI脚本'/var/www/backend/backend/wsgi.py'加载为Python模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55353284/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com