I'm trying to deploy a django app to elastic beanstalk. Beanstalk can't find the settings
file when loading wsgi.py
. I've seen this in a few other SO questions, but none of those solved my issue.
I get the following error:
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.
These are the contents of the 02_python.config
file under .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/"
And this is what the directory structure looks like:
It seems to pick up the WSGIPath okay, so I'm not sure why it can't pick up the django settings module path.
It might be looking into the parent kairos_app
directory.
Try changing
DJANGO_SETTINGS_MODULE: "kairos_app.prod_settings"
into
DJANGO_SETTINGS_MODULE: "kairos_app.kairos_app.prod_settings"
OR
"PYTHONPATH": "/opt/python/current/app/kairos_app:$PYTHONPATH"
into
"PYTHONPATH": "/opt/python/current/app/kairos_app/kairos_app:$PYTHONPATH"
The latter impacts the whole runtime, so it might break things.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.