Simple Flask App Blueprint: Basic Edition (Python, Flask, PostgreSQL, et al. deployed on Heroku)
Python HTML Mako
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Simple App Blueprint: Basic

The Simple App Blueprint: Basic (dupped sab-basic) will help you get started with an easy to learn, yet powerful technology stack. A stack that you can have up and running in less than 5 minutes, so you can focus on making the real thing. It includes a database, shows how to insert and retreive info from that database, and have it all deployed on Heroku.

Technology Stack

Getting Started

Accelerate your next web project and start with this Simple App Blueprint for the basics. For now, this Getting Started how-to is for written for OSX.

1. Setup your development environment

  1. Install virtualenv

    1. $ sudo pip install virtualenv
  2. Install virtualenvwrapper

    1. $ sudo pip install virtualenvwrapper
    2. $ export WORKON_HOME=~/Envs
    3. $ mkdir -p $WORKON_HOME
    4. $ source /user/local/bin/
  3. Clone the repository and create a working directory

    1. $ git clone
    2. $ mv sab-basic projectname
    3. $ cd projectname
  4. Create virtual environment

    1. $ mkvirtualenv projectname
    2. Update postactate file:
      1. $ nano $VIRTUAL_ENV/bin/postactivate
      2. Add (and modify) the following line: cd ~/path/to/your/project
      3. Add: export APP_SETTINGS="config.DevelopmentConfig"
  5. Install Packages

    1. pip install -r requirements.txt

2. Create GitHub and Heroku App and Repositories

  1. Setup Github Repository

    1. Create a new repostitory in your Github account
    2. Change the remote origin to point to your new repository: $ git remote set-url origin
  2. Install Heroku Toolbelt and git it configured

    1. Follow
  3. Create Staging environment on Heroku

    1. $ heroku create projectname-staging
    2. $ git remote add staging
    3. $ heroku config:set APP_SETTINGS=config.StagingConfig --remote staging
  4. Create Production environment on Heroku

    1. $ heroku create projectname-production
    2. $ git remote add production
    3. $ heroku config:set APP_SETTINGS=config.ProductionConfig --remote production

3. Setup and Initialize Database

  1. Setup local database

    1. Download and install
    2. Open and open psql
    3. Create new database:
      1. Run in psql: CREATE DATABASE projectname;
    4. Update local configuration:
      1. $ nano $VIRTUAL_ENV/bin/postactivate
      2. Add: export DATABASE_URL="postgresql://localhost/projectname"
    5. Restart environment: $ workon projectname
  2. Initialize and run database migrations

    1. delete the directory named 'migrations'
    2. $ python db init
    3. $ python db migrate
    4. $ python db upgrade
  3. Setup databases on Heroku

    1. Create databases:
      1. $ heroku addons:add heroku-postgresql:hobby-dev --app projectname-staging
      2. $ heroku addons:add heroku-postgresql:hobby-dev --app projectname-production
    2. Commit database migration and push to staging and live
      1. $ git add .
      2. $ git commit -a -m "Database migrations"
      3. $ git push staging master
      4. $ git push production master
    3. Run database migrations:
      1. $ heroku run python db upgrade --app projectname-staging
      2. $ heroku run python db upgrade --app projectname-production

4. Deploy

  1. Run locally

    1. Open
    2. $ workon projectname
    3. $ python runserver
    4. Open in your browser: http://localhost:5000/
  2. Deploy and run on staging

    1. Push latest version to staging: $ git push staging master
    2. Open in your browser:
  3. Deploy and run on production

    1. Push latest version to production: $ git push production master
    2. Open in your browser:

Make it your own!

That was easy right? You are ready to go modify and built your next killer app. Few points to keep in mind:

  1. Don't forget to commit your code and push to Github as backup ($ git push origin master)
  2. Run $ flake8 projectname to get feedback on coding style
  3. Deploy to staging as final test ($ git push staging master)
  4. Finally: deploy to product ($ git push production master)


Thanks to Flask by Example on Real Python, written by Cam Linke for the basics and learning me to do this.

Questions / Feedback?

If you have questions or feedback, do not hesitate to use the Issues tool in this repository.