SHARE
TWEET

Untitled

a guest Aug 12th, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. To use PostgreSQL as your database in Python applications you will need to use the psycopg2 package.
  2. $ pip install psycopg2
  3. $ pip freeze > requirements.txt
  4. And use this package to connect to DATABASE_URL in your code:
  5. import os
  6. import psycopg2
  7. import urlparse
  8.  
  9. urlparse.uses_netloc.append("postgres")
  10. url = urlparse.urlparse(os.environ["DATABASE_URL"])
  11.  
  12. conn = psycopg2.connect(
  13.     database=url.path[1:],
  14.     user=url.username,
  15.     password=url.password,
  16.     host=url.hostname,
  17.     port=url.port
  18. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top