gpt4 book ai didi

python - 目标 WSGI 脚本无法作为 Python 模块加载到 Django 应用程序中

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:00 25 4
gpt4 key购买 nike

来 self 的 Apache 错误日志。

[Tue Jan 26 00:37:50.840680 2016] [:error] [pid 6522] [client 70.70.241.146:57247] mod_wsgi (pid=6522): Target WSGI script '/var/www/site/public_html/project/apache/wsgi.py' cannot be loaded as Python module.
[Tue Jan 26 00:37:50.840791 2016] [:error] [pid 6522] [client 70.70.241.146:57247] mod_wsgi (pid=6522): Exception occurred processing WSGI script '/var/www/site/public_html/project/apache/wsgi.py'.
[Tue Jan 26 00:37:50.840852 2016] [:error] [pid 6522] [client 70.70.241.146:57247] Traceback (most recent call last):
[Tue Jan 26 00:37:50.841081 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "/var/www/site/public_html/project/apache/wsgi.py", line 23, in <module>
[Tue Jan 26 00:37:50.841094 2016] [:error] [pid 6522] [client 70.70.241.146:57247] application = get_wsgi_application()
[Tue Jan 26 00:37:50.841252 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "/opt/env/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Tue Jan 26 00:37:50.841264 2016] [:error] [pid 6522] [client 70.70.241.146:57247] django.setup()
[Tue Jan 26 00:37:50.841400 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "/opt/env/lib/python3.4/site-packages/django/__init__.py", line 17, in setup
[Tue Jan 26 00:37:50.841412 2016] [:error] [pid 6522] [client 70.70.241.146:57247] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Jan 26 00:37:50.841619 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "/opt/env/lib/python3.4/site-packages/django/conf/__init__.py", line 48, in __getattr__
[Tue Jan 26 00:37:50.841632 2016] [:error] [pid 6522] [client 70.70.241.146:57247] self._setup(name)
[Tue Jan 26 00:37:50.841672 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "/opt/env/lib/python3.4/site-packages/django/conf/__init__.py", line 44, in _setup
[Tue Jan 26 00:37:50.841682 2016] [:error] [pid 6522] [client 70.70.241.146:57247] self._wrapped = Settings(settings_module)
[Tue Jan 26 00:37:50.841715 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "/opt/env/lib/python3.4/site-packages/django/conf/__init__.py", line 92, in __init__
[Tue Jan 26 00:37:50.841725 2016] [:error] [pid 6522] [client 70.70.241.146:57247] mod = importlib.import_module(self.SETTINGS_MODULE)
[Tue Jan 26 00:37:50.842007 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
[Tue Jan 26 00:37:50.842054 2016] [:error] [pid 6522] [client 70.70.241.146:57247] return _bootstrap._gcd_import(name[level:], package, level)
[Tue Jan 26 00:37:50.842088 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Tue Jan 26 00:37:50.842112 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Tue Jan 26 00:37:50.842135 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
[Tue Jan 26 00:37:50.842158 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[Tue Jan 26 00:37:50.842181 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Tue Jan 26 00:37:50.842203 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Tue Jan 26 00:37:50.842225 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
[Tue Jan 26 00:37:50.842247 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[Tue Jan 26 00:37:50.842269 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Tue Jan 26 00:37:50.842291 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Tue Jan 26 00:37:50.842313 2016] [:error] [pid 6522] [client 70.70.241.146:57247] File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
[Tue Jan 26 00:37:50.842346 2016] [:error] [pid 6522] [client 70.70.241.146:57247] ImportError: No module named 'mysite'

然后在我的主机文件中:

WSGIScriptAlias / /var/www/site/public_html/project/apache/wsgi.py
<Directory "/var/www/site/public_html/project/apache">
Require all granted
</Directory>
Alias /static/ /var/www/site/public_html/app/static

<Directory /var/www/site/public_html/app/static>
Require all granted
</Directory>

在 VirtualHost 之外:

WSGIPythonPath /var/www/site/public_html/:/opt/env/lib/python3.4/site-packages

这是wsgi.py:

import os, sys

apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append(project)

sys.path.append('/var/www/site/public_html/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.apache.override'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我已经尝试过 sudo apt-get install libapache2-mod-wsgi-py3。我已经更改了 python 路径。不确定还能尝试什么。

接下来我可以去哪里看?

我在 Ubuntu 14 上。

最佳答案

您已将 DJANGO_SETTINGS_MODULE 设置为“mysite.apache.override”,但您没有任何名为“mysite”的东西;你的项目是“project”,所以你的设置模块在“project.apache.override”中。

另请注意,您真的不应该将代码放在 public_html 下,最好根本不要放在/var/www 下;它不应该在任何可能被网络服务器错误地直接提供的地方。

关于python - 目标 WSGI 脚本无法作为 Python 模块加载到 Django 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35009885/

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