Getting started with Heroku
I wanted to make a simple web app using Python and Flask. It turns out launching an app for all the world to see is quick and easy with Heroku. I figured out what I needed at minimum to run my app via Heroku and thought I’d present my files here for future reference.
If you don’t have it already, setup Heroku
Heroku allows you to launch any number of applications. At the free tier level you get 1 dyno per app. This is sufficient to test a simple web app.
Create a new Heroku app
You can create a new app in the web interface, and the dashboard will show you how to clone the repo for your new app to your local machine. Then, you just need to add all your application files (for example, the 4 files shown below) to the repository and push them up to Heroku. Once you push, the app should be live at [your-new-app-name].herokuapp.com.
Files for a Python 2 / Flask application
There’s 4 files here. I’ve shown the filenames (in bold) and what’s in each file. To understand more about what’s going on refer to Heroku’s documentation and read about the web server, Gunicorn.
Procfile
web: gunicorn hello:app
requirements.txt
Flask==0.12
gunicorn==19.0.0
runtime.txt
python-2.7.13
hello.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def my_func():
return 'Hello, World!'