Maybe ... but not recommended ... You can access the current connection handler ...
Use something like this:
from django.db import connections if not alias in connections.databases: connections.databases[alias] = connections.databases['default'] # Copy 'default' connections.databases[alias]['NAME'] = alias
Make sure that you are not trying to add a new alias to the database dictionary when there is ANY database activity in the current thread.
The problem you need to overcome is that this code will need to be hosted somewhere, as it will always be affected by the current thread before trying to access the database. For this, I use middleware.
source share