How to Deploy a Flask app on Heroku? | Part - 1

Hari Prasad
featurepreneur
Published in
2 min readMay 24, 2021

In this Article, We gonna deploy a Flask app on Heroku

Let me show you, How to do that.

Let’s get started

1. Go to Heroku Website and Create a New Account.

2. Install Heroku CLI

3. Open Terminal and enter the below command.

heroku login

It will ask you to press any key to open up the browser.

Press enter, It will automatically open the browser.

Now, press the login button in the browser.

4. Create a new app by entering the below command. This will create a git repository in Heroku.

Note: The app name should be unique.

heroku apps:create your-project-name

5. Create a New Folder, Go inside it and Initialize it as Git Repository.

mkdir your-folder-name
cd your-folder-name
git init
heroku git:remote -a your-project-name

6. Create a Flask app

touch app.py
nano app.py

Write your code

A sample code is given below:

from flask import Flaskapp = Flask(__name__)

@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run(debug=True)

Press Ctrl + X and Enter.

7. Create Procfile and requirements.txt

Procfile

web: gunicorn app:app

requirements.txt

flask
gunicorn

8. Commit and push the files

git add .
git commit -am "make it better"
git push heroku master

It will start the deployment process and looks like this

... 
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 52.7M
remote: -----> Launching...
remote: Released v3
remote: https://{your-project-name}.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/{your-project-name}.git
ae85864..4e63b46 master -> master

Now, open the browser and paste the given URL of your app into the browser

https://{your-project-name}.herokuapp.com/

I hope this was helpful to you, I will see you in the next article on How to deploy a Dockerized Flask app in Heroku.

Thank you for reading this article.

--

--