我正在尝试学习如何使用AWS Ubuntu机器设置Django web服务器,我已经解决了我的一些问题,但现在我正在受到ModuleNotFoundError的打击:没有名为'tutorial'的模块,我也得到了500内部服务器错误。
以下是我认为必要的代码:error.log
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()
default000.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