Tommaso Lazzari
Tommaso Lazzari

Reputation: 93

Deploying Flask App on Heroku

I apologize in advance if it is a massive mistake. I created Flaskr, the Flask tutorial App http://flask.pocoo.org/docs/0.12/tutorial/packaging/#tutorial-packaging, on the local server it works fine but when I try to deploy the app on Heroku, Heroku responds "Application error". I am using the same file structure of the tutorial i just added a Procfile in the root of my app. The Procfile contains the following lines:

export FLASK_APP=flaskr.py
export FLASK_DEBUG=true
flask run

Logs give no errors, dyno is running fine, but the app is not running. Any suggestion? Is Heroku even the best way to deploy this app?

Upvotes: 1

Views: 2289

Answers (1)

Grey Li
Grey Li

Reputation: 12762

Procfile is used to start application or execute other command, you have to declare a web process to start Heroku server, it should like this:

web: gunicorn -k gevent app:app

Or without gevent:

web: gunicorn app:app

You can also add gunicorn option:

web: gunicorn -w 4 app:app

Also, gunicorn and gevent(optional) should be included in your requirements.txt file.

In the code above, the first app is python file's name (i.e.app.py), the second is the application instance's name (i.e.app = Flask(__name__)).

Here is a Flask application template for heroku: https://github.com/zachwill/flask_heroku

Upvotes: 6

Related Questions