Skip to content

Instantly share code, notes, and snippets.



Created Mar 15, 2014
What would you like to do?
Postgresql config for local and heroku with peewee ORM
#heroku config:set HEROKU=1
import os
import urlparse
import psycopg2
from flask import Flask
from flask_peewee.db import Database
if 'HEROKU' in os.environ:
DEBUG = False
url = urlparse.urlparse(os.environ['DATABASE_URL'])
'engine': 'peewee.PostgresqlDatabase',
'name': url.path[1:],
'user': url.username,
'password': url.password,
'host': url.hostname,
'port': url.port,
DEBUG = True
'engine': 'peewee.PostgresqlDatabase',
'name': 'framingappdb',
'user': 'postgres',
'password': 'postgres',
'host': 'localhost',
'port': 5432 ,
'threadlocals': True
app = Flask(__name__)
db = Database(app)

This comment has been minimized.

Copy link

@thepythonist99 thepythonist99 commented Dec 8, 2017

Thanks for this awesome post. I have been trying to host my Flask App which contains Postgresql as database on Heroku but in vain.
I used your post to solve the problem but when I launch my app on Heroku, it doesn't use the statements in the 'if' condition, rather it uses the one in 'else'. What might be wrong ?
I also notice you import pyscopg2 and not using it; Is there something you were trying to do with the module ?


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment