Deploying a Flask Application to Heroku
Introduction
In this tutorial you will learn how to deploy a Flask application to Heroku. The app can be as simple as a “Hello World” app to a social media monitoring platform!
Nowadays there is no business that doesn’t have a web app to help it a reach greater audience, or maybe provide its services through an online portal.
Today you are about to learn how to make an API using Flask as a case study for how to deploy your app on Heroku.
Building a REST API with Flask
In your project directory, let’s start off by creating a virtualenv:
$ python -m venv venv/
And let’s activate it with the source
command:
$ source venv/bin/activate
Then, let’s use pip
to install the libraries we’re going to use – flask
to build the app and gunicorn
as our server:
$ pip install flask
$ pip install gunicorn
Our application is going to be a simple API that receives a name and returns a welcome message:
# app.py
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/getmsg/', methods=['GET'])
def respond():
# Retrieve the name from url parameter