Advertisement
Guest User

Untitled

a guest
Aug 12th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  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. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement