A memorandum for touching python Flask on heroku

Heroku x Flask (Python) is the fastest personally when making a trivial api, but I'll summarize it because it always takes time to mystery by default.

Local preparation

First, make an app on Heroku

mkdir "Folder name"
cd "Folder name"
git init 
heroku create -a "app name"

Three files are required in the created folder

First, from requirements.txt (ver after == is appropriate)

requirements.txt


Flask==1.1.0
gunicorn==19.9.0
psycopg2==2.7.6.1

psycopg2 is a library for tampering with postgresql, so it is unnecessary when you do not mess with postgresql Others are required if you use Flask

Next is Procfile

Procfile


web: gunicorn hello:app --log-file -

最後はhello.py

hello.py


# -*- coding: utf-8 -*-
# -------------------------------------------------------------------
#
#   hello.py
#
#                       Mar/04/2020
# -------------------------------------------------------------------
import os
from flask import Flask,request

app = Flask(__name__)

@app.route("/")
def hello():
    str_out = ""
    str_out += "<h2>Hello from Python!</h2>"
    str_out += "<blockquote>"
    str_out += "Hello<p />"
    str_out += "</blockquote>"
    str_out += "Mar/04/2020 14:40<br />"
#
    return str_out

#Only needed when testing locally, not on the server
if __name__ == "__main__":
    port = int(os.environ.get("PORT", 5000))
    app.run(host='0.0.0.0', port=port)

# -------------------------------------------------------------------

Deploy

git add .
git commit -m "First Commit"
git push heroku master

Originally you have to set python as buildpack, but it seems that heroku will recognize Python and download the latest version of python when you push it.

If it works, you should see "Hello From Python" with the command below.

heroku open

the end

Recommended Posts

A memorandum for touching python Flask on heroku
A memorandum of stumbling on my personal HEROKU & Python (Flask)
Next, use Python (Flask) for Heroku!
A memo of a tutorial on running python on heroku
A story about running Python on PHP on Heroku
Build a Python extension for E-Cell 4 on Windows 7 (64bit)
[Heroku] Memo for deploying Python apps using Heroku on Windows [Python]
I tried python on heroku for the first time
Procedure for building a CDK environment on Windows (Python)
A memorandum about correlation [Python]
A memorandum about Python mock
A note on touching Microsoft's face recognition API in Python
(Failure) Deploy a web app made with Flask on heroku
[GCP] A memorandum when running a Python program on Cloud Functions
Build a Python extension for E-Cell 4 on Mac OSX (Yosemite)
Create a Python script for Wake on LAN (NAT traversal Wake on LAN [5])
Create a virtual environment for python on mac [Very easy]
Build a python environment on CentOS 7.7 for your home server
Building a Python environment on Mac
Building a Python environment on Ubuntu
[Python] A memorandum of beautiful soup4
Create a Python environment on Mac (2017/4)
python + django + scikit-learn + mecab (1) on heroku
Deploy Flask app on heroku (bitterly)
Create a python environment on centos
Python json.loads () returns str on Heroku
Deploy the Flask app on Heroku
Install confluent-kafka for Python on Ubuntu
Deploy the Flask app on heroku
Build a python3 environment on CentOS7
Periodically run Python on Heroku Scheduler
A memorandum of understanding for the Python package management tool ez_setup
Easy! Implement a Twitter bot that runs on Heroku in Python
I made a Nyanko tweet form with Python, Flask and Heroku
Things to watch out for when creating a Python environment on a Mac
Python memorandum
Notes on nfc.ContactlessFrontend () for nfcpy in python
Build a python environment on MacOS (Catallina)
Python Memorandum 2
Create a python environment on your Mac
Let's create a virtual environment for Python
Favicon placement (when using Python, Flask, Heroku)
Impressions of using Flask for a month
A memo with Python2.7 and Python3 on CentOS
Map rent information on a map with python
Build a version control environment for Python, Ruby, Perl, Node.js on UNIX
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
Memorandum on how to use gremlin python
Python memorandum
Make Qt for Python app a desktop app
[GCP] Procedure for creating a web application with Cloud Functions (Python + Flask)
Launch a Flask app in Python Anywhere
python memorandum
Get a token for conoha in python
A little more detail on python comprehensions
Easy web app with Python + Flask + Heroku
python memorandum
A tool for easily entering Python code
Run Python code on A2019 Community Edition
A story about deploying a Twitter-linked app created using Flask + gunicorn on Heroku