[PYTHON] Deploy the Flask app on Heroku

Overview

Here are the steps to deploy the smallest Flask app on Heroku.

Prerequisites

procedure

Create the required resources

Create a directory to put the project files and move to the directory.

$ mkdir flaskonheroku
$ cd flaskonheroku

Create the required files.

$ touch app.py Procfile

Edit app.py as follows.

# -*- coding: utf-8 -*-
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return 'hello, world'

if __name__ == '__main__':
    app.run()

Edit the Procfile as follows.

web: gunicorn app:app --log-file=-

Check if it works in the local environment

$ python app.py
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Access the address and OK if there is no problem.

Create the files needed for deployment

Create requirements.txt.

$ pip freeze > requirements.txt

Edit requirements.txt as follows.

Click==7.0
Flask==1.1.1
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
Werkzeug==0.16.0

Preparing the git repository

Initialize as a git repository.

$ git init
$ git add .
$ git commit -m "first commit"

Creating a Heroku app

Log in to Heroku and create an app.

$ heroku login
$ heroku create

Deploy the app to Heroku

A remote repository has been created, so push it.

$ git remote
heroku
$ git push heroku master

Check the app

Open the app and check.

$ heroku open

Recommended Posts

Deploy the Flask app on Heroku
Deploy the Flask app on heroku
Deploy Flask app on heroku (bitterly)
Deploy the Django app on Heroku [Part 2]
Deploy masonite app on Heroku 2020
Run the app with Flask + Heroku
(Failure) Deploy a web app made with Flask on heroku
Run the flask app on Cloud9 and Apache Httpd
Miscellaneous notes about deploying the django app on Heroku
How to deploy a web app made with Flask to Heroku
How to deploy the easiest python textbook pybot on Heroku
Detect app releases on the App Store
How to deploy a Django app on heroku in just 5 minutes
Deploy flask app with mod_wsgi (using pipenv)
Deploy Django api on heroku (personal note)
[Python] Run Flask on Google App Engine
Easy web app with Python + Flask + Heroku
Change the order of PostgreSQL on Heroku
Getting Started with Heroku, Deploying Flask App
Launch Flask application with Docker on Heroku
[First personal development] The story of deploying the Flask app and Twitter's automatic reply bot on Heroku
Django Heroku Deploy 1
Redis on Heroku
Notes on Flask
shimehari on heroku
Django Heroku Deploy 2
A story about deploying a Twitter-linked app created using Flask + gunicorn on Heroku
A memorandum for touching python Flask on heroku
Deploy a Python 3.6 / Django / Postgres web app on Azure
Until you run a Flask application on Google App Engine for the time being
I tried python on heroku for the first time
Deploy a Django application on Google App Engine (Python3)
jsonschema validation on flask
Deploy a Django app made with PTVS on Azure
Django-Overview the tutorial app on Qiita and add features (1)
Deploy a web app created with Streamlit to Heroku
A memorandum of stumbling on my personal HEROKU & Python (Flask)
Sample to put Python Flask web app on Azure App Service (Web App)
Deploy your Go app on Google App Engine with GitHub Actions
Deploy the strongest front-end Streamlit for data scientists on Azure!
Django --Overview the tutorial app on Qiita and add features (2)
Touch Flask + run with Heroku
Install the JDK on Linux
Watch the video on Fedora31
Paste the link on linux
Deploy django project to heroku
Publish the site for free on Google App Engine (personal memorandum)
The record I was addicted to when putting MeCab on Heroku
[Python + heroku] From the state without Python to displaying something on heroku (Part 1)
The road to installing Python and Flask on an offline PC
[Python + heroku] From the state without Python to displaying something on heroku (Part 2)
Deploy Flask servers on virtual machines such as Azure and AWS