Created
March 15, 2014 02:44
-
-
Save fprieur/9561148 to your computer and use it in GitHub Desktop.
Postgresql config for local and heroku with peewee ORM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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