I'm currently trying to develop a simple python web application on Heroku and I'm trying to connect to the Heroku Postgres database. I've managed to connect, but only through using the database url Heroku provides:

from flask import Flask
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

app = Flask(__name__)
engine = create_engine('postgres://[email protected]:XXX')
Base = declarative_base()
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

Is there a way to connect to the Heroku database through my python code without having to include the exact url? Thanks!

share|improve this question
    
Why don't you want to use the uri? – davidism Aug 11 '15 at 2:13
    
I don't think I was implementing it correctly. Do you happen to have an example implementation of it for Flask? – Jonathan Aug 11 '15 at 2:26
    
Consider using Flask-SQLAlchemy to handle the database internals for you. Beyond that, what you were doing looks fine. – davidism Aug 11 '15 at 2:28
    
great! it seems to be working. Thanks! – Jonathan Aug 11 '15 at 14:56
    
I was having trouble connecting to Postgres and this solved the problem for me: github.com/kennethreitz/flask-heroku – joshlsullivan Aug 12 '15 at 14:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.