简体   繁体   中英

Deploying Django to AWS - WSGIPath refers to a file that does not exist

I've been struggling with getting Django and AWS to work together. I'm following the tutorial here:

https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/

I've been following all the tutorial steps, including using the "eb option" command to change the WSGIPath, but I keep getting the error:

"ERROR: Your WSGIPath refers to a file that does not exist."

As far as I can tell I've been doing everything exactly according to the tutorial.

The relevant part of my config file looks like this:

NumProcesses: '1'
NumThreads: '15'
StaticFiles: /static/=static/
WSGIPath: iotd/iotd/wsgi.py

What am I doing wrong?

我在遇到此错误时发现的一件事是,如果您的存储库是 git 存储库,则必须跟踪和提交 .ebextensions 文件夹,否则将无法在 eb deploy 上正确提取。

I have read the realpython blog post that you referred to. I would also refer you to the AWS tutorial. It is written for the deployment of a bare bones Django project and it can be found at:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html#python-django-configure-for-eb

I found it useful to work through, and learned a great deal fixing the error you have identified. Of course the fix is related to my own implementation of the tutorial, which I followed step-by-step. I have read other posts that talk to this issue, but the solution stated here was not provided in those posts, as far as I can tell.

An abbreviated version of the tutorial follows to provide some context for the comments made here. This abbreviated version begins after creating/activating the virtual environment, but before its activation.

$ mkdir ed_django_app
$ . venv/Scripts/activate
(venv)[~eb_django_app]$ django-admin startproject django_eb
(venv)[~eb_django_app/django_eb]$ python manage.py migrate
(venv)[~eb_django_app/django_eb]$ python manage.py runserver
(venv)[~eb_django_app]$ pip freeze > requirements.txt
(venv)[~eb_django_app]$ deactivate
[~eb_django_app]$ eb init –region us-east-1

After the "eb init" command the .elasticbeanstalk directory, along with some files, are created in the initialization process. In that directory you will find the config.yml file. Its contents are:

branch-defaults:
  default:
    environment: eb-django-dev
global:
  application_name: eb_django_app
  default_ec2_keyname: myec2keyname
  default_platform: Python 2.7
  default_region: us-east-1
  profile: eb-cli
  sc: null

The tutorial directs the developer to then create a directory called .ebextensions and create the 01-eb_django.config file:

option_settings:
  "aws:elasticbeanstalk:application:environment":
    DJANGO_SETTINGS_MODULE: "django_eb.settings"
    PYTHONPATH: "/opt/python/current/app/django_eb:$PYTHONPATH"
  "aws:elasticbeanstalk:container:python":
    WSGIPath: "django_eb/django_eb/wsgi.py"

This is YAML and the indentation matters. At least 1 space indent. In this case there are 2 spaces of indent at each level. The WSGIPath is set correctly. It is important to make sure the directory structure is the same as what is indicated in the tutorial.

In the tutorial the "eb create" command is now issued, and as you noted, the following arises:

ERROR: WSGIPath refers to a file that does not exist

The problem that was identified existed in the config.yml where there is the key-pair for application_name:

global:
  application_name: eb_django_app

It was changed to:

global:
  application_name: django_eb

This resolved the ERROR for me.

Using eb :

eb config

Go to aws:elasticbeanstalk:container:python: and change WSGIPath from:

application.py

to

mysite/wsgi.py

With "mysite" being your application name ofcourse

possible solution error : Your WSGIPath refers to a file that does not exist

after following this tutorial: https://realpython.com/deploying-a-django-app-to-aws-elastic-beanstalk/

I got the error when I was uploading my protect to aws. The step that I forgot was to activate my virtual env and from my there type the command 'eb deploy'

note : this error can also occur in different circumstances

This in django.config file, say your app name is 'yourappname', worked for me.

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: yourappname.wsgi:application

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM