Skip to content

Instantly share code, notes, and snippets.

@fprieur
Created March 15, 2014 02:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fprieur/9561148 to your computer and use it in GitHub Desktop.
Save fprieur/9561148 to your computer and use it in GitHub Desktop.
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
urlparse.uses_netloc.append('postgres')
url = urlparse.urlparse(os.environ['DATABASE_URL'])
DATABASE = {
'engine': 'peewee.PostgresqlDatabase',
'name': url.path[1:],
'user': url.username,
'password': url.password,
'host': url.hostname,
'port': url.port,
}
else:
DEBUG = True
DATABASE = {
'engine': 'peewee.PostgresqlDatabase',
'name': 'framingappdb',
'user': 'postgres',
'password': 'postgres',
'host': 'localhost',
'port': 5432 ,
'threadlocals': True
}
app = Flask(__name__)
app.config.from_object(__name__)
db = Database(app)
@thepythonist99
Copy link

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 ?

Thanks

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