Deploy Flask to HEROKU - With Samples
Tags: flask, heroku, webdev
Published: 2020-09-14 10:59:09

---
title: Deploy Flask to HEROKU - With Samples
published: true
description: Learn how to deploy a simple Flask application to HEROKU. 
tags: flask, heroku, webdev
cover_image: https://raw.githubusercontent.com/app-generator/static/master/docs/deploy-flask-on-heroku.jpg
---
Hello Coders, 

This article explains how to **deploy [Flask](https://palletsprojects.com/p/flask/) to [HEROKU](https://www.heroku.com/)**, a popular Platform-as-a-Service provider (PaaS) which makes it easy for developers to deploy apps in different technologies and frameworks. The platform supports all major languages like Python, Ruby, Java, PHP, and popular frameworks (**Flask** included).
To provide something useful, the article comes with a few deployment-ready samples, developed by [AppSeed](https://appseed.us/?ref=dev) and released under the MIT License on Github. 

---

> **Thank you for reading!** TL;DR; - Links & Resources

- [Flask](https://palletsprojects.com/p/flask/) - the official website
- [HEROKU](https://www.heroku.com/) - the official website
- Sample #1 - [LIVE Demo](https://flask-dashboard-argon.appseed.us/) - [Flask Dashboard Argon](https://appseed.us/admin-dashboards/flask-boilerplate-dashboard-argon) (product page) 
- Sample #2 - [LIVE Demo](https://flask-illustrations-webpixels.appseed.us/) - [Flask App Webpixels](https://appseed.us/apps/flask-apps/flask-illustrations-webpixels) (product page) 
- Sample #3 - [LIVE Demo](https://flask-dashboard-dattaable.appseed.us/) - [Flask Dashboard - DattaAble](https://appseed.us/admin-dashboards/flask-dashboard-dattaable) (product page)
- Support via Github & [Discord](https://discord.gg/fZC6hup) - provided by AppSeed

---

![Deploy Flask to HEROKU - Argon Dashboard a free sample project.](https://raw.githubusercontent.com/app-generator/static/master/blog/deploy-flask-to-heroku-argon-dashboard-intro.gif) 

---

## [What is Flask](https://docs.appseed.us/what-is/flask/)

**Short-note for beginners** - Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. Classified as a microframework, Flask is written in Python and it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions.

--- 

> Set up PC for Flask

Being a Python framework, Flask requires Python to run and expose his magic. Install Python is fairly simple via the official installers available on the official [download](Being a Python framework, Flask requires Python to run and expose his magic.) page.

After installer execution, just open a terminal window and type `python --version`. On my PC, this command return:

```bash
$ python --version
Python 3.8.5
``` 

Once Python is installed, we can use `PIP`, the official package manager for Python, to install Flask: 

```bash
$ pip install Flask
```

---

## [What is HEROKU](https://docs.appseed.us/what-is/heroku/)

HEROKU is a popular platform that automates the deployment for apps coded on many languages like Python, GO, Ruby, JAVA, Php, and frameworks (Flask included).

To get started the first thing is to create an account on the HEROKU platform and install the command-line interface that matches our OS.

---

**HEROKU - [Sign Up page](https://signup.heroku.com/)**

![HEROKU - Sign Up page.](https://raw.githubusercontent.com/app-generator/static/master/docs/heroku-sign-up-page.jpg)

---

**HEROKU - [Instal CLI](https://devcenter.heroku.com/articles/heroku-cli)**

![HEROKU - Instal CLI.](https://raw.githubusercontent.com/app-generator/static/master/docs/heroku-install-cli.jpg)

---

We can check the installation by typing `heroku -v` in the console. Any output that's not an error, means we are on the good track. On my PC, the output looks as below: 

```bash
$ heroku -v
heroku/7.42.13 win32-x64 node-v12.16.2
```

From this point, we can move forward with our sample apps. The source code is published on Github and the recommended way to download the samples is to use `GIT` command-line tool. If your workstation doesn't have GIT installed, the apps can be downloaded as ZIP archives.  

---

## Flask HEROKU Sample #1 - Black Dashboard

[Flask Black Dashboard](https://appseed.us/admin-dashboards/flask-dashboard-black) is an open-source, production/deployment-ready starter released under the MIT License on Github. I will iterate below the relevant files that make the HEROKU deployment possible with just a few lines written in the terminal.

---

**#1** [runtime.txt](https://github.com/app-generator/flask-black-dashboard/blob/master/runtime.txt) — specify the Python version to be used

```bash
python-3.6.10
```

---

**#2** [Procfile](https://github.com/app-generator/flask-black-dashboard/blob/master/Procfile) — the HEROKU app bootstrapper

```bash
web: gunicorn run:app --log-file=-
```

---

The above line instructs HEROKU to use the Gunicorn WSGI server to execute the WSGI app object, returned by [run.py](https://github.com/app-generator/flask-black-dashboard/blob/master/run.py), located at the root of the project.

```python
# Contents of run.py
from flask_migrate import Migrate
from os import environ
... 
app = create_app( app_config )
Migrate(app, db) 
# At this point, app is the WSGI object that Gunicorn expects.
```

---

The `gunicorn` module must be also present in the [requirements.txt](https://github.com/app-generator/flask-black-dashboard/blob/master/requirements.txt) file, along with other modules required by the app.

```txt
flask
flask_login
...
python-decouple
gunicorn          # <--- The magic line
```

---

With all configuration in place, we can start the deployment by typing a few lines in the terminal. 

---

**#1** Clone the source code

```bash
$ git clone https://github.com/app-generator/flask-black-dashboard.git
$ cd flask-black-dashboard
```

---

**#2** HEROKU Login - this will trigger a new browser window

```bash
$ heroku login
```

---

**#3** Create the app in HEROKU world

```bash
$ # Create the app with a random name
$ heroku create 
$
$ # Create app using a name
$ heroku create you-name-here
```

---

**#4** Compile the app in HEROKU environment. This step might take a while.

```bash
$ git push heroku master
```

---

**#5** Open the app in the browser

```bash
$ heroku open
```

At this point, the sample app should be visible in the browser.

![Flask Dashboard - Black Design, free starter coded in Flask by AppSeed.](https://raw.githubusercontent.com/app-generator/flask-black-dashboard/master/media/flask-black-dashboard-screen.png)

---

## Flask HEROKU Sample #2 - Webpixels

This Flask starer is provided with database, ORM, a simple codebase, and deployment scripts (HEROKU included).
The project [README](https://github.com/app-generator/flask-illustrations-webpixels/blob/master/README.md) contains all the necessary information to compile the app in a local environment and also to deploy the app on HEROKU with a few lines of code:

---

```bash
$ # Clone the source code:
$ git clone https://github.com/app-generator/flask-illustrations-webpixels.git
$ cd flask-illustrations-webpixels
$
$ # Check Heroku CLI is installed
$ heroku -v
heroku/7.25.0 win32-x64 node-v12.13.0 # <-- All good
$
$ # Check Heroku CLI is installed
$ heroku login
$ # this command will open a browser window - click the login button (in browser)
$
$ # Create the Heroku project
$ heroku create
$
$ # Trigger the LIVE deploy
$ git push heroku master
$
$ # Open the LIVE app in browser
$ heroku open
```

---

Once the browser is triggered to open a new page, we should see Flask Webpixels running.

---

![Flask Webpixels - simple Flask application, deployed on HEROKU.](https://raw.githubusercontent.com/app-generator/flask-illustrations-webpixels/master/media/flask-illustrations-webpixels-screen.png)

---

## Flask HEROKU Sample #3 - DattaAble

This open-source admin dashboard coded in Flask with a basic set of features can be deployed instantly on HEROKU just by typing the same commands as for the previous samples: 

---


```bash
$ # Clone the source code:
$ git clone https://github.com/app-generator/flask-dashboard-dattaable.git
$ cd flask-dashboard-dattaable
$
$ # Check Heroku CLI is installed
$ heroku -v
heroku/7.25.0 win32-x64 node-v12.13.0 # <-- All good
$
$ # Check Heroku CLI is installed
$ heroku login
$ # this command will open a browser window - click the login button (in browser)
$
$ # Create the Heroku project
$ heroku create
$
$ # Trigger the LIVE deploy
$ git push heroku master
$
$ # Open the LIVE app in the browser
$ heroku open
```

By visiting the browser, our sample Flask starter should be usable. Just create a new user and authenticate it. 

---

![Flask HEROKU deployment - DattAble Dashboard, a sample project provided by AppSeed.](https://raw.githubusercontent.com/app-generator/static/master/blog/deploy-flask-to-heroku-dattaable-dashboard-intro.gif)


---

Using HEROKU for deployment might be a good solution for fast deployment without touching the server environment not only for Flask apps. As mention in the first paragraph, HEROKU can be used for Django, Nodejs, or JAVA web applications. More information can be found by accessing the official docs:   

- [HEROKU](https://www.heroku.com/) - the official website
- [HEROKU Docs](https://devcenter.heroku.com/)

---

```python
print('Thank you!')
```