我正在尝试将Django应用程序部署到弹性beantalk。加载settings
时,Beanstalk找不到wsgi.py
文件。我在其他一些SO问题中也看到了这一点,但这些问题都没有解决我的问题。
我收到以下错误:
ModuleNotFoundError: No module named 'kairos_app.prod_settings'
Target WSGI script '/opt/python/current/app/kairos_app/kairos_app/wsgi.py' cannot be loaded as Python module.
这些是02_python.config
下.ebextensions
文件的内容:
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python3 kairos_app/manage.py migrate --noinput"
leader_only: true
02_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python3 kairos_app/manage.py collectstatic --noinput"
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "kairos_app.prod_settings"
"PYTHONPATH": "/opt/python/current/app/kairos_app:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: kairos_app/kairos_app/wsgi.py
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
这是目录结构的样子:
似乎可以选择WSGIPath,所以我不确定为什么不能选择django设置模块路径。
它可能正在寻找父kairos_app
目录。
尝试更改
DJANGO_SETTINGS_MODULE: "kairos_app.prod_settings"
进入
DJANGO_SETTINGS_MODULE: "kairos_app.kairos_app.prod_settings"
OR
"PYTHONPATH": "/opt/python/current/app/kairos_app:$PYTHONPATH"
进入
"PYTHONPATH": "/opt/python/current/app/kairos_app/kairos_app:$PYTHONPATH"
后者会影响整个运行时,因此可能会破坏事情。