Skip to content

Instantly share code, notes, and snippets.

@emilyhorsman
Created May 21, 2015 20:52
Show Gist options
  • Save emilyhorsman/66e3f6b8f0ca7508ae47 to your computer and use it in GitHub Desktop.
Save emilyhorsman/66e3f6b8f0ca7508ae47 to your computer and use it in GitHub Desktop.
Setting up Heroku/Python/postgres/Flask
import os
from flask import Flask
from playhouse.flask_utils import FlaskDB
DATABASE = os.environ["DATABASE_URL"]
app = Flask(__name__)
app.config.from_object(__name__)
database = FlaskDB(app)
from app import app, database
from models import Foo
from views import *
if __name__ == "__main__":
database.database.create_table([Foo], safe=True)
app.run()
from playhouse.flask_utils import FlaskDB
from peewee import *
from app import database
class Foo(database.Model):
text = CharField()
web: gunicorn main:app --log-file=-

Postgres on OS X locally

http://postgresapp.com/

New project

mkdir project
virtualenv --no-site-packages project
cd project
source bin/activate
pip install Flask gunicorn psycopg2 peewee
git init
heroku create
heroku addons:create heroku-postgresql:hobby-dev
export DATABASE_URL=$(heroku config:get DATABASE_URL)
from app import app
from models import Foo
@app.route("/")
def index():
return "bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment