/pyFlaskDeploymentGuide

📓 A simplified guide for deploying a python Flask app to Heroku

pyFlaskDeploymentGuide

This guide assumes you have a working Python Flask app and have Heroku-CLI installed on your machine.

  1. Install the gunicorn server: pip install gunicorn

  2. Install all other dependencies:

pip install flask
pip install flask-sqlalchemy
pip install pandas
...
  1. Run the command:
pip freeze > requirements.txt

This command will create a requirements.txt file in the current directory that includes all our dependencies (Python packages we use). Heroku will use this file to install all the required dependencies for our app.

  1. Create a Procfile file (command: touch Procfile).

  2. Open (edit) Procfile and add the following line to it:

web: gunicorn <app-folder-name>.app:app

(replacing <app-folder-name> with the name of the folder that contains your __init__.py file)

This file will be used by Heroku to start the gunicorn server and run our app.

  1. Using the command-line login to heroku: heroku login and enter your credentials.

  2. Create an Heroku app with the command: heroku create

  3. Add, Commit and Push your app to Heroku:

git add .
git commit -m 'heroku deployment'
git push heroku master
  1. You are now successfully deployed!