Reputation: 2436
I have a flask application that I have configured as a python module.
To explain further, this is a simplified structure of my project:
project_dir
ven
dir_a
dir_b
flask_app
__init__.py
__main__.py
# __main__.py
.
.
.
app = create_app(...)
client = Client(app)
.
.
.
print("Hello World")
running_app = app.run("0.0.0.0", port=5000)
When I want to run my application, I hit python -m dir_a.dir_b.flask_app
Now I want to run it with gunicorn.
For your reference, this is a sample of running gunicorn
gunicorn -w 1 -b 0.0.0.0:5000 **wsgi:server**
If I want to run the application, from project_dir I run
python -m dir_a.dir_b.flask_app
How should I run my application with gunicorn in my case?
Please note that I want "Hello World" to be printed before running the application
What I have tried:
gunicorn -w 1 -b 0.0.0.0:5000 dir_a.dir_b.flask_app:running_app
I then removed the line running_app = app.run("0.0.0.0", port=5000)
and tried
gunicorn -w 1 -b 0.0.0.0:5000 dir_a.dir_b.flask_app:app
and
gunicorn -w 1 -b 0.0.0.0:5000 dir_a.dir_b.flask_app:create_app(...)
None of them worked
Upvotes: 3
Views: 3881
Reputation: 5264
You need to tell gunicorn what app to run
The app.run()
method is for the development server, so first you’ll have to comment it out or just delete it.
And then
gunicorn -w 1 -b 0.0.0.0:5000 dir_a.dir_b.flask_app:app
Or you could import the app further up in the module.
Upvotes: 1