【发布时间】:2021-07-20 15:35:25
【问题描述】:
我正在尝试在 pythonanywhere 上托管我的本地 Web 应用程序。 [Django 和网络开发初学者]
我在启动应用程序时遇到以下错误:
Error running WSGI application
2021-04-26 21:46:32,020: ModuleNotFoundError: No module named 'myapp'
2021-04-26 21:46:32,020: File "/var/www/username_pythonanywhere_com_wsgi.py", line 16, in <module>
2021-04-26 21:46:32,020: application = get_wsgi_application()
2021-04-26 21:46:32,020:
2021-04-26 21:46:32,020: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2021-04-26 21:46:32,020: django.setup(set_prefix=False)
2021-04-26 21:46:32,020:
2021-04-26 21:46:32,020: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/__init__.py", line 19, in setup
2021-04-26 21:46:32,021: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2021-04-26 21:46:32,021:
2021-04-26 21:46:32,021: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
2021-04-26 21:46:32,021: self._setup(name)
2021-04-26 21:46:32,021:
2021-04-26 21:46:32,021: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup
2021-04-26 21:46:32,021: self._wrapped = Settings(settings_module)
2021-04-26 21:46:32,021:
2021-04-26 21:46:32,021: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__
2021-04-26 21:46:32,021: mod = importlib.import_module(self.SETTINGS_MODULE)
文件位置:
settings.py 文件位于:
/home/username/WebDev/Website/Django/MyApp/myapp/myapp
我已将 '/var/www/username_pythonanywhere_com_wsgi.py' 文件修改为:
"""
WSGI config for myapp 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
import sys
sys.path.append("/home/username/WebDev/Website/Django/MyApp/myapp")
os.environ('DJANGO_SETTINGS_MODULE', 'myapp.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我在 stackoverflow 上查看了类似的问题,但仍然无法弄清楚我到底出了什么问题。
任何指针/帮助将不胜感激。
【问题讨论】:
标签: django wsgi python-3.8 pythonanywhere