문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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

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.

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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top