I practice set up Django under Elastic Beanstalk from there document.
But There is error.
ERROR Your WSGIPath refers to a file that does not exist.
My directory like this:
-djangoenv (where I use git)
- mysite
-manage.py
-mysite
-__init__.py
-settings.py
-urls.py
-wsgi.py
and My the .elasticbeanstalk/optionsettings.djapp file like this :
And .ebextensions/python.config like this , I don't know where to put this .try several times still not work . I try mysite/mysite/wsgi.py still not work
container_commands:
01_syncdb:
command: "django-admin.py syncdb --noinput"
leader_only: true
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: mysite/wsgi.py
- option_name: DJANGO_SETTINGS_MODULE
value: mysite.settings
Please tell me how and where to set my wsgi path ??
Thank you very much!
I found that you have to restart the server for it to take these changes into consideration.
I spent ages changing and tweaking these options and nothing worked. Then when I went to the EB console and restarted the environment it worked.
In the server you are about to deploy the django application to elasticbean stalk. Run:
eb config
Then replace the application.py to mysite/wsgi.py and save the changes.
After the update, you may do:
git add.
git commit -m "some updates"
eb deploy
After successfully update the environment, you may view the changes in elasticbeanstalk, under your enviroment, go to the instance and check the setting in Configuration, then view the WSGIPath under Software Configuration.
Disclaimer: This information is valid until 4 November 2016. AWS may further change the setting.
The path specified should be relative to the .elasticbeanstalk directory.
The correct path should be mysite/mysite.wsgi.py. option_settings: is:
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: mysite/mysite/wsgi.py
- option_name: DJANGO_SETTINGS_MODULE
value: mysite.settings
You have WSGIPath set to "application.py" but your WSGI file is "mysite/wsgi.py".
You should try
mysite.wsgi:application and make sure you are in the mysite first folder while deploying your application
Related
I have been going through every thread on here and have tried all the ways I can think of. I am following the AWS deploy django tutorial and keep getting this error
ERROR Your WSGIPath refers to a file that does not exist.
I have used eb config to edit the file to the same path thats in django.config which is endjango/wsgi but nothing I have tried has worked. Also tried wrapping it in quotes and that did not work either.
Heres my file
django.config
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: ebdjango/wsgi.py
Config.yml
branch-defaults:
default:
environment: django-env
group_suffix: null
global:
application_name: django-tutorial
branch: null
default_ec2_keyname: aws-eb
default_platform: python-3.6
default_region: us-east-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
repository: null
sc: null
workspace_type: Application
Figured out the issue ebextensions and requirements.txt need to be in root folder. Next run eb config and edit wsgi path to match endjango/wsgi.py.
You can also configure your wsgi path from UI. Go to configure tab and edit it there. Another option is using terminal.
I'm stuck trying to solve a "403 Forbidden" error in my Elastic Beanstalk Flask application. I have set up my python.config file as below:
option_settings:
aws:elasticbeanstalk:container:python:staticfiles:
"/static/": "/static/"
"/templates/": "/templates/"
commands:
01_set_file_permissions:
command: "chmod 777 /opt/python/current/app/static/"
The static folder was initially giving a 404 but the static files section of python.config fixed that. My problem is I can't get the file permissions to be recognised on the server. It always returns a 403 error. Please help.
I worked out the fix. The option_settings section was incorrect in that the route to folder was not given as a relative path. Also the /static/ folder was already set via a hard-coded value in the AWS console at:
AWS > Elastic Beanstalk > > Configuration > Software Configuration > Virtual Path. I needed to change the value of /static/ to static/ here.
Finally the commands section was not required at all. The fixed python.config file (that works) is as follows:
option_settings:
aws:elasticbeanstalk:container:python:staticfiles:
"/templates/": "templates/"
Where should the DJANGO_SETTINGS_MODULE environment variable be set?
Multiple possible locations:
In a config file (.ebextensions) as follows:
option_settings: aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "app.settings"
In the wsgi.py file before application is loaded
In manage.py (I also see this on different Django projects on the web)
If I don't specify it in wsgi.py, it looks like it can't be found at all. Therefore, I wonder if the environment variables set in .ebextensions are set before wsgi.py is loaded.
Any idea?
Introduce your wsgi.py in a config file in .ebextensions
django_aws_eb.config:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: "my_site/wsgi.py"
Specifly your DJANGO_SETTING_MODULE in your `wsgi.py' file
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_site.settings")
application = get_wsgi_application()
aws beanstalk first looks for configs in .ebextension to then locate wsgi.py to then locate settings.
more info: Configure Your Django Application for Elastic Beanstalk
I am using this tutorial:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
I create the .ebextensions directory inside the root directory, and put this django.config file in it:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: mysite/wsgi.py
I've also tried setting the path to mysite/mysite/wsgi.py because I saw that work somewhere but it did not help me.
Everywhere I look shows a different .config file with different arrangements, and I don't know where to go from here. How can I properly set my WSGIPath in Elastic Beanstalk?
[Solution]
1 eb config
2 Change the WSGIPath there from application.py to mysite/wsgi.py
That's It
I ran into a similar issue, and it seemed to resolve when I put .elasticbeanstalk in the same directory as .ebextensions, rather than having it be a child directory. Then I had to run eb config to fix the wsgi file that it was de facto picking up, and now I have a running app.
Make sure that .ebextensions isn't ignored. EB looks for .ignore file (.ebignore by default and if it doesnt exists but .gitignore does, it will use it) and deploy only the files that are not ignored. Had a similar issue with my local_settings.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-ebignore
I did not use console but GUI.
ERROR: Your WSGIPath refers to a file that does not exist.
where could be problem : Creating .zip file
select all : files of your project (not the project folder)
Note : weworkout is my django project (created by django-admin startproject
weworkout)
Right way : select all files
Wrong way : selecting project folder
Also this is the only change you have to do to your django project before uploading
weworkout/.ebextensions/django.config file contains
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: weworkout/wsgi.py
Note : .ebextensions is in same folder as manage.py
If you see the following error:
ERROR: Your WSGIPath refers to a file that does not exist.
Note the following:
EC2 (server) instances in EB (platform) run Apache.
Apache finds Python apps according to our WSGIPATH.
By default EB assumes the WSGI file is called application.py.
There are two ways of correcting this.
Option 1: Using environment-specific configuration settings
Run: $ eb config
Find the following config file “.elasticbeanstalk/src-test.env.yml.”
This file doesn’t actually exist locally; EB pulled it so that you can edit it.
If you save changes in this pseudo-file, EB will update the corresponding settings in your env.
If you search for the terms ‘WSGI’ in the file, you should find a config section resembling this:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: application.py
Update the WSGIPath:
aws:elasticbeanstalk:container:python:
NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: src/src/wsgi.py #src/src is an example. Do not just c&p.
If you save the file, EB will update the env config automatically.
The advantage to using the $ eb config method to change settings is that you can specify different settings per env.
Option 2: Using global configuration settings
To use this option, create a new file called /.ebextensions/02_python.config:
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: “src.settings" #src is an example.
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" #src is an example.
"aws:elasticbeanstalk:container:python":
WSGIPath: src/src/wsgi.py #src is an example.
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
What’s happening?
DJANGO_SETTINGS_MODULE: "src.settings" - adds the path to the settings module.
"PYTHONPATH": "/opt/python/current/app/src:$PYTHONPATH" - updates our PYTHONPATH so Python can find the modules in our application.(Note that the use of the full path is necessary.)
WSGIPath: src/src/wsgi.py sets our WSGI Path.
NumProcesses: 3 and NumThreads: 20 - updates the number of processes and threads used to run our WSGI application.
"/static/": "www/static/" sets our static files path.
Run $ git commit (if necessary) and $ eb deploy to update these settings.
Check if your Django.config file was saved with the correct extension. I had the same issue and the problem was that the file was being saved as a TXT file instead of config file.
After some changes in my repo and deploy to heroku I am receiving the following error:
ImportError: No module named site
I not have idea what can cause the problem because I only change some Django templates in the last 2 commits.
Best Regards
Take a look at your Procfile. It should show something like this:
web: gunicorn site:app
Make sure site is the name of your app.
Heroku has an article for this: https://help.heroku.com/BWJ7QYTF/why-am-i-seeing-importerror-no-module-named-site-when-deploying-a-python-app
Updates to the Python buildpack mean that the PYTHONPATH and PYTHONHOME config vars being set on the app may introduce this issue.
Firstly, check if these are present with
heroku config
To fix the issue, you can unset them like so:
heroku config:unset PYTHONHOME -a appname
heroku config:unset PYTHONPATH -a appname
Add the following to your proc file
web: gunicorn site:app
Also check your gitignore and make sure site isnt included