![](/img/trans.png)
[英]flask tutorial troubleshooting: ModuleNotFoundError: No module named 'app'
[英]ModuleNotFoundError: No module named 'tutorial'
我正在嘗試學習如何使用 AWS Ubuntu 機器設置 Django web 服務器,我已經解決了一些問題,但現在我遇到了 ModuleNotFoundError: No module named 'tutorial' 我也得到了 500內部服務器錯誤。
這是我認為必要的代碼是:
錯誤日志
GNU nano 6.2 /home/ubuntu/django-project/site/logs/error.log
[Mon Jan 16 19:35:18.750368 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] mod_wsgi (pid=10330): Failed to exec Python script file '/home/ubuntu/djang>
[Mon Jan 16 19:35:18.750441 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] mod_wsgi (pid=10330): Exception occurred processing WSGI script '/home/ubun>
[Mon Jan 16 19:35:18.750979 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] Traceback (most recent call last):
[Mon Jan 16 19:35:18.751031 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "/home/ubuntu/django-project/src/tutorial/wsgi.py", line 16, in <mod>
[Mon Jan 16 19:35:18.751037 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] application = get_wsgi_application()
[Mon Jan 16 19:35:18.751043 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751048 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] django.setup(set_prefix=False)
[Mon Jan 16 19:35:18.751053 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751058 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Jan 16 19:35:18.751068 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751073 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] self._setup(name)
[Mon Jan 16 19:35:18.751078 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751083 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] self._wrapped = Settings(settings_module)
[Mon Jan 16 19:35:18.751088 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "/home/ubuntu/django-project/venv/lib/python3.10/site-packages/djang>
[Mon Jan 16 19:35:18.751092 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Jan 16 19:35:18.751097 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_mod>
[Mon Jan 16 19:35:18.751102 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] return _bootstrap._gcd_import(name[level:], package, level)
[Mon Jan 16 19:35:18.751107 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[Mon Jan 16 19:35:18.751112 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[Mon Jan 16 19:35:18.751117 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
[Mon Jan 16 19:35:18.751122 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_remo>
[Mon Jan 16 19:35:18.751128 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[Mon Jan 16 19:35:18.751133 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[Mon Jan 16 19:35:18.751146 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlock>
[Mon Jan 16 19:35:18.751161 2023] [wsgi:error] [pid 10330:tid 139960159290944] [remote 136.41.64.54:40330] ModuleNotFoundError: No module named 'tutorial'
wsgi.py
"""
WSGI config for tutorial project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings')
application = get_wsgi_application()
默認000.conf
<VirtualHost *:80>
ErrorLog /home/ubuntu/django-project/site/logs/error.log
CustomLog /home/ubuntu/django-project/site/logs/access.log combine
<Directory /django-project/src/tutorial>
Require all granted
</Directory>
WSGIDaemonProcess tutorial python-home=/home/ubuntu/django-project/venv python-path=/home/ubuntu/django-project/src/tutorial/
WSGIProcessGroup tutorial
WSGIScriptAlias / /home/ubuntu/django-project/src/tutorial/wsgi.py
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
MY folder layout
── site
│ ├── logs
│ │ ├── access.log
│ │ └── error.log
│ └── public
│ ├── media
│ └── static
├── src
│ ├── db.sqlite3
│ ├── manage.py
│ └── tutorial
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-310.pyc
│ │ ├── settings.cpython-310.pyc
│ │ ├── urls.cpython-310.pyc
│ │ └── wsgi.cpython-310.pyc
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── venv
├── bin
│ ├── __pycache__
我正在按照說明指南進行操作,但左右都遇到了錯誤,我只想將我的 mysql 和 django 鏈接到我的頁面上。
根據您的文件,您的項目名稱是“tutorial”,錯誤是由
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tutorial.settings')
在 wsgi.py 中(但這是正確的 - 根本原因在於您的非標准文件夾結構)。 您的文件夾結構如何?
應該按照django標准:
src/
tutorial/
tutorial/
settings.py
urls.py
wsgi.py
從您的 Apache 配置中,我可以看到 wsgi.py 不在正確的文件夾中。
應該:
WSGIScriptAlias / /home/ubuntu/django-project/src/tutorial/tutorial/wsgi.py
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.