7

What I'am trying to do is to use 2 databases in my django app. One is to be accessed from a remote server. Django settings has something like this

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'snackvoxadmin'
    },
    'users': {
        .....
    }


}

The database user has a url like similar to this one: postgres://a78adj1he81....

2 Answers 2

11

You can decompose your database url and configure it like this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydatabase',
        'USER': 'mydatabaseuser',
        'PASSWORD': 'mypassword',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

And the pattern for a database url is :

postgres://user:password@host:post/database

https://docs.djangoproject.com/en/1.8/ref/settings/#databases


Or you can use the package dj-database-url to directly use the database url.

E.g. from readme :

import dj_database_url
DATABASES = {'default': dj_database_url.parse('postgres://...')}
Sign up to request clarification or add additional context in comments.

2 Comments

Cool! Now I just have to work on the relations. Thanks a lot!
I was using the same with heroku and now i moved to pythonanywhere are postrgres db from neon, though the things work fine locally, app connects with the remote db but on pythonanywhere, it fails. It gives a connection error,
1

That URL presumably consists of a username, a password, and a host name/IP address. You could split them up yourself or use the dj-database-url library.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.