Here are the steps to deploy the smallest Flask app on Heroku.
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=-
$ 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 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
Initialize as a git repository.
$ git init
$ git add .
$ git commit -m "first commit"
Log in to Heroku and create an app.
$ heroku login
$ heroku create
A remote repository has been created, so push it.
$ git remote
heroku
$ git push heroku master
Open the app and check.
$ heroku open
Recommended Posts