Book Image

Learning Heroku Postgres

By : Patrick Rafael de Oliveira Espake
Book Image

Learning Heroku Postgres

By: Patrick Rafael de Oliveira Espake

Overview of this book

Table of Contents (17 chapters)
Learning Heroku Postgres
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Keyword List
Index

Connecting with Django


To connect to PostgreSQL using the Django framework it is necessary to install the dj-database-url package and add it in the dependency file called requirements.txt.

$ pip install dj-database-url
$ pip freeze > requirements.txt

Then add the following code at the bottom of settings.py file:

import dj_database_url 
DATABASES['default'] = dj_database_url.config()

In the deploy process, the DATABASE_URL variable will be parsed and converted into a form that Django can understand.