Is there a way I can tell Django2 to use a different database (and cache/session store) depending on a parameter in the URL?
Note that I have read the docs related to multiple databases en Django (https://docs.djangoproject.com/en/2.1/topics/db/multi-db/#automatic-database-routing), and that is not what I'm asking.
The docs are showing an example about how to use DATABASE_ROUTERS
, which is a way of choosing which database should be used programatically when using a model.
What I'm asking is how can I make Django2 use different databases automatically depending on a parameter in the URL. Example:
http://foo.bar/usa <-- use USA database
http://foo.bar/europe <-- use Europe database
Edit: to whoever is marking this question as duplicate.Please read carefully what I'm asking.
First of all, I'm asking to do this automatically, versus the programatically solution that was provided as an answer in Django - Runtime database switching
Second, I'm asking for database, session/cookies and cache storage, which is quite different than just changing the database for model queries.