1

I want to connect Django to a database that the user will set in the main page.

The user will have to precise the engine (with a combobox), the database, login, password etc in a form, and I want to proceed the connection with the submit.

So far, I tried to set "DATABASES = {}" in settings.py, but it returns an error.

Have you got any clue about how to do it?

4

1 回答 1

0

You have to connect your app to a database.

There is no way that I know of to change the database connection dynamically. The only things I can think of are a bit convoluted:

  1. If you want to change your back-end database: I would suggest having a separate setting file for the database (I will call it dbsettings.py) that you will include in the settings file. At the submit, you would lunch a script that will change the dbsettings.py file, and restart the django server (with a CLI call for example)

  2. If the database is user specific, configure and fire up another django instance, and have the two instances communicate (you could use celery for messaging or django commands)

I (and other people) may come up with better solutions if we had a little more details

于 2012-10-25T14:08:03.167 回答