ModuleNotFoundError: No module named 'test_proj.settings'
ModuleNotFoundError: No module named 'test_proj.settings'
我正在尝试在 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'
由于 settings.py 存在于 test_proj 包中,我无法弄清楚为什么会这样正在抛出异常。
- 我不知道这是最好的方法,但它解决了我的问题
- 我所做的是更改文件夹结构
- 我以前的文件夹结构是这样的 this
- 我像 this 一样通过移动 [django] -> [ProjectName] 中的所有文件来更改它
-> [项目名称] 到 [django] -> [项目名称]
- 但我认为可能有一种方法可以通过改变路径来解决这个问题。但我是 django 的新手,我 post 在我解决问题后
我正在尝试在 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'
由于 settings.py 存在于 test_proj 包中,我无法弄清楚为什么会这样正在抛出异常。
- 我不知道这是最好的方法,但它解决了我的问题
- 我所做的是更改文件夹结构
- 我以前的文件夹结构是这样的 this
- 我像 this 一样通过移动 [django] -> [ProjectName] 中的所有文件来更改它 -> [项目名称] 到 [django] -> [项目名称]
- 但我认为可能有一种方法可以通过改变路径来解决这个问题。但我是 django 的新手,我 post 在我解决问题后