简体   繁体   中英

How to use Gunicorn with Flask

I'm trying to deploy my flask app at Heroku but I am facing a problem with Procfile. I was reading an article where there have this as file.

app.py

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "<h1>Hello, World</h1>"

Then in Procfile it's like that:

web: gunicorn app:app

And it work, Tough me it's not the case, My folder structure is like that:
In flask_simple_app folder

├── run.py
└── simple_app
    ├── __init__.py
    ├── routes.py
    ├── static
    │   └── style.css
    └── templates
        ├── base.html
        └── home.html

run.py contain following lines:


from simple_app import app

if __name__ == '__main__':
    app.run()

init .py contain following lines:


from flask import Flask

app = Flask(__name__)

from simple_app import routes

routes.py contain following lines:


from simple_app import app
from flask import render_template

@app.route("/")
def home():
    return render_template('home.html')

So my question is to know where I should put Procfile and how I'm gonna write this:

web: gunicorn ...:...

It should be:

  • web: gunicorn module_name_where_app_instance_exists:name_of_the_app_instance

In your case:

  • web: gunicorn run:app

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