我正在尝试在 cPanel 78.0.45 上部署django应用。参见Setup Python App Configuration here。 djangoapp 是应用程序根目录。 djangoapp 目录的结构如下:
__pycache__/
passenger_wsgi.cpython-37.pyc
log
passenger_wsgi.py
public
tmp
test_proj/ /*the name of django app*/
test_proj/
__init__.py
__pycache__
settings.py
urls.py
wsgi.py
manage.py
passenger_wsgi.py 的脚本是:
import imp
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
wsgi = imp.load_source('wsgi', 'test_proj/test_proj/wsgi.py')
application = wsgi.application
wsgi.py 的脚本是:
"""
WSGI config for test_proj 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/2.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_proj.settings')
application = get_wsgi_application()
manage.py 的脚本是:
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_proj.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
现在的问题是,当我点击应用程序URL时,它显示this。我检查了日志以跟踪问题,它引发了以下异常:
App 36033 output: ModuleNotFoundError
App 36033 output: : No module named 'test_proj.settings'
由于 test_proj 软件包中存在 settings.py ,因此我无法弄清为什么会引发此异常。