Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dj-database-url while connecting with postgresql in heroku using python

I'm here because I'm really really new with heroku-python-django-postgresql group. I have googled for a usage for dj-database-url and I don't understand why i have to use it when developing a python application that needs to connect with postgresql. I have added postgresql (dev version) as add-on to my application, but I don't know how to tell to the app that I want it to use my db.

so, the short question is, How do I indicate to dj-database-url that I want to use my database?

Thanks for your time and answers, I'll appreciate your help because this is very very urgent!

like image 521
ada.pineda Avatar asked Jun 03 '12 05:06

ada.pineda


People also ask

How do I access Heroku Postgres database in Python?

First, open a terminal and navigate to your app. Then use the command heroku addons to check what addons you currently have installed. Now you can add the Postgres database using heroku addons:create heroku-postgresql:hobby-dev . Naturally, if you want a different plan, substitute that in for hobby-dev .

What is DJ database URL?

dj-database-url.md This is focused on setting up a development environment. Production will be similar but instead of using the default DB location and credentials, you should use the location of the actual DB server and you really ought to be using a secret password.


1 Answers

dj-database-url is a utility to help you load your database into your dictionary from the DATABASE_URL environment variable. Heroku uses environment variables for your database and other addons. To begin using your database you'd simply use the below command to setup your DATABASES dictionary:

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

And maybe stash DATABASE_URL in your virtualenv activate script.

like image 122
CraigKerstiens Avatar answered Oct 02 '22 20:10

CraigKerstiens