loading...

How to Deploy a Flask app on Heroku.

techparida profile image Trilochan Parida Updated on ・2 min read

Hello Friends, In this article I will show you how to deploy a flask app on Heroku. Follow the below steps to deploy your python flask app on Heroku.

Prerequisite:

  1. You must have installed Git in your system.
  2. You must have installed Python in your system.

Step-1: Install Heroku CLI

% brew tap heroku/brew && brew install heroku

Above command is for Mac, for other systems you can click here

Step-2: Create Python Virtual Environment

% python3 -m venv foldername
% source foldername/bin/activate
% cd foldername

Step-3: Install Flask & Gunicorn

% pip3 install flask gunicorn

Step-4: Create an app folder and simple python app

% mkdir app
% cd app
% vi main.py

main.py

from flask import Flask
app= Flask(__name__)
@app.route('/')
def index():
  return "<h1>Welcome to CodingX</h1>"

Step-5: Create an entry point to the application, wsgi.py

% cd ../
% vi wsgi.py

wsgi.py

from app.main import app
if __name__ == "__main__":
  app.run()

Step-6: Run the application in your local system

% python wsgi.py

Step-7: Create requirements.txt and Procfile file

% pip3 freeze
% pip3 freeze > requirements.txt
% vi Procfile

Procfile

web: gunicorn wsgi:app

Step-8: Create an app in Heroku

Heroku new app

Step-9: Deploy your app to heroku

% heroku login
% git init
% heroku git:remote -a codingx-python
% git add.
% git commit -am "First python app"
% git push heroku master

Step-10: Open your application on browser

https://app-name.herokuapp.com

It's done!

Please Subscribe to my Youtube Channel https://youtube.com/c/codingx

Posted on by:

techparida profile

Trilochan Parida

@techparida

#TechEntrepreneur, Passionate about #technology #coding, Love to #troubleshoot #travel

Discussion

markdown guide
 

Thank you, Very good. More people should focus on succinct explanations like this.