Skip to content
Related Articles

Related Articles

Deploy Python Flask App on Heroku
  • Difficulty Level : Medium
  • Last Updated : 19 Feb, 2020

Flask is a web application framework written in Python. Flask is based on the Werkzeug WSGI toolkit and Jinja2 template engine. Both are Pocco projects. This article revolves around how to deploy a flask app on Heroku. To demonstrate this, we are first going to create a sample application for a better understanding of the process.


  • Python
  • pip
  • Heroku CLI
  • Git

Deploying Flask App on Heroku

Let’s create a simple flask application first and then it can be deployed to heroku. Create a folder named “eflask” and open the command line and cd inside the “eflask” directory. Follow the following steps to create the sample application for this tutorial.

STEP 1 : Create a virtual environment with pipenv and install Flask and Gunicorn .

$ pipenv install flask gunicorn 

STEP 2 : Create a “Procfile” and write the following code.

$ touch Procfile 

STEP 3 : Create “runtime.txt” and write the following code.

$ touch runtime.txt 

STEP 4 : Create a folder named “app” and enter the folder.

$ mkdir app
$ cd app

STEP 5 : Create a python file, “” and enter the sample code.


from flask import Flask
app = Flask(__name__)
def home_view():
        return "<h1>Welcome to Geeks for Geeks</h1>"

STEP 6 :Get back to the previous directory “eflask”.Create a file“” and insert the following code.

$ cd ../
$ touch

from app.main import app
if __name__ == "__main__":

STEP 7 : Run the vitual environment.

$ pipenv shell 

STEP 8 : Initialize an empty repo, add the files in the repo and commit all the changes.

$ git init 
$ git add .
$ git commit -m "Initial Commit"

STEP 9 : Login to heroku CLI using

heroku login

Now, Create a unique name for your Web app.

$ heroku create eflask-app

STEP 10 : Push your code from local to the heroku remote.

$ git push heroku master

Finally, web app will be deployed on

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :