Context:
As Farzad has said, just rename 'app.py' or 'application.py' or whatever name you have saved the application file to 'main.py'. If you can't change then create another project with the same code but this time with application file names as 'main.py'
Simply rename your main python app (for me it was app.py) to main.py. Google Cloud requires main.py to begin the process.
By default, App Engine looks for an app
variable in a file called main.py
. You have two options: put your WSGI app where App Engine expects it to be, or define a custom entrypoint:
You can create a file called main.py
that has an app
variable which is simply imported and aliased from the correct location:
from demosite.wsgi import main as app
From https://cloud.google.com/appengine/docs/standard/python3/config/appref:
entrypoint
: Optional. The command that is executed when your app starts. For your app to receive HTTP requests,entrypoint
should contain a command which starts a web server that listens on the port specified by the PORT environment variable. If you do not specify anentrypoint
, App Engine will configure and start the Gunicorn webserver.
By default it's this:
entrypoint: gunicorn -b :$PORT main:app
You would need something like:
entrypoint: gunicorn -b :$PORT demosite.wsgi:main
See here for more details about application startup: https://cloud.google.com/appengine/docs/standard/python3/runtime#application_startup
Adding:
The main.py have to be in root of your application, where app.yaml is.
And the content, can to be, as well:
from mysite.wsgi import application
# App Engine by default looks for a main.py file at the root of the app
# directory with a WSGI-compatible object called app.
# This file imports the WSGI-compatible object of your Django app,
# application from mysite/wsgi.py and renames it app so it is discoverable by
# App Engine without additional configuration.
# Alternatively, you can add a custom entrypoint field in your app.yaml:
# entrypoint: gunicorn -b :$PORT mysite.wsgi
app = application