user3629142
user3629142

Reputation:

Can django use an external database?

Can django use an external database? I mean, if you have one server for the db and other n-servers with the web server, can django use the db on an external machine? Can django do queries via internet to another django db?

Upvotes: 2

Views: 14550

Answers (4)

I reach this post, but in my case, I need to access another database. My intention is create an application that report informationa from another database. I needed to use two databases. I found the way in the django documentation.

https://docs.djangoproject.com/en/3.2/topics/db/multi-db/

Upvotes: 0

dhana
dhana

Reputation: 6525

Yes you can access the database from anywhere. But they(you) need to provide database privileges for your IP. some code is like,

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

You can also use external django package https://github.com/kennethreitz/dj-database-url for deployment.

Upvotes: 1

DM Graves
DM Graves

Reputation: 819

Yes, your database and web server can be on separate servers. You just have to specify in your settings file the host. See https://docs.djangoproject.com/en/dev/ref/settings/#databases

Upvotes: 6

loopbackbee
loopbackbee

Reputation: 23322

As the relevant documentation states, Django is capable of using multiple databases. Whether remote access is supported will depend on which one you choose to use - but, as a general rule, it is supported, with the notable exception of sqlite

Upvotes: 1

Related Questions