How to deploy a Flask app with Peewee to Heroku
Python HTML
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
templates
.gitignore
Procfile
README.md
requirements.txt
server.py
tellytubbies.py

README.md

Deploying the app to Heroku and provisioning a database

Pre-requisites

  1. Install Heroku CLI.
  2. Optionally, install psql if you want to connect to the Postgres database on Heroku from the command line.

Steps

Deploying the app

  1. Clone this repository:
    $ git clone git@github.com:swifthorseman/flask-peewee-heroku-setup.git
  2. Create the app on Heroku and deploy it:
    $ heroku login
    $ heroku create
    $ git push heroku master

Running heroku create will generate the name and the URL from which it can be accessed.

Setting up a new database

  1. Create a new database on Heroku as an add-on to the app:
    $ heroku addons:create heroku-postgresql:hobby-dev
    Verify that the database has been created by running:
    $ heroku pg:info
  2. Set up a config variable:
    $ heroku config:set HEROKU=1
  3. Verify that the required environment variables are set:
    $ heroku config
    The values for both DATABASE_URL and HEROKU should be set.

Creating a table on the database

  1. Launch a shell on Heroku:

    $ heroku run bash
  2. Run:

    $ python tellytubbies.py
  3. From a local shell, verify that the table was created successfully:

    $ heroku pg:info

    The command should output the number tables (1) and the number of rows (4).

  4. Use psql to connect to the database and query the tables:

    $ heroku pg:psql
    
    ::DATABASE=> \dt
              List of relations
     Schema |    Name    | Type  |     Owner
    --------+------------+-------+----------------
     public | tellytubby | table | sgaluyzmzkklpj
    (1 row)
    ::DATABASE=> select * from tellytubby;
         id |    name     | colour
        ----+-------------+--------
          1 | Tinky Winky | Purple
          2 | Dipsy       | Green
          3 | Laa-Laa     | Yellow
          4 | Po          | Red
    (4 rows)
    

Connecting to the app through the URL (which was generated when heroku create was run) will retrieve entries from the database and display them in the browser.