Tuesday, 10 September 2013

How to use one of many DATABASES setting in Django

How to use one of many DATABASES setting in Django

I have many identical database instances
localhost
test.server.com
test2.server.com
www.server.com
I want my Django settings to be able to chose any one of these with
minimal efforts. I don't want to keep multiple setting files.
I know I can configure them like this but how to switch to anyone other
than the default.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'HOST': 'localhost'
},
'test': {
'ENGINE': 'django.db.backends.sqlite3',
'HOST': 'test.server.com'
},
'test2': {
'ENGINE': 'django.db.backends.sqlite3',
'HOST': 'test2.server.com'
},
'production': {
'ENGINE': 'django.db.backends.sqlite3',
'HOST': 'www.server.com'
}
}

No comments:

Post a Comment