I wrote the Flask application using the application factory pattern. This means that it does not automatically create an application instance when importing. You must call create_app for this. Now, how do I run it in Gunicorn?
Create a file wsgi.py under your project with the following, and point Gunicorn to it.
from my_project import create_app
app = create_app()
Copy the code
gunicorn -w 4 my_project.wsgi:app # original command
# -w 4 specifies four worker processes
Copy the code
If you are using the application factory mode, Gunicorn allows you to specify function calls like my_project:create_app(). In most cases, you can skip the steps of making wsgi.py files and show Gunicorn how to create your application directly.
gunicorn -w 4 "my_project:create_app()"
Copy the code
Note that in some parentheses with special meaning, quotation marks are required.