Reputation: 1796
In django, most multi-tenant implementations (modules) are mapping hosts onto views.
e.g. mapping host/URL -> django view using postgress schema's:
customer1.myapp.com/view1/arg1 -> myapp.view1(arg1) using schema 'customer1'
customer2.myapp.com/view1/arg1 -> myapp.view1(arg1) using schema 'customer2'
customer3.myapp.com/view1/arg1 -> myapp.view1(arg1) using schema 'customer3'
Since my PaaS (Pythonanywhere) is not supporting wildcard domains (*.myapp.com), I am trying to set up a multi-tenant application using URL mapping:
e.g. mapping URL -> django view:
myapp.com/customer1/view1/arg1 -> myapp.view1(arg1) passing implicit parameter tenant='customer1'
myapp.com/customer2/view1/arg1 -> myapp.view1(arg1) passing implicit parameter tenant='customer2'
myapp.com/customer3/view1/arg1 -> myapp.view1(arg1) passing implicit parameter tenant='customer3'
Here some middleware should take care of passing the tenant parameter to the view and filtering query results for objects applicable to the selected tenant. e.g. https://django-tenant-schemas.readthedocs.io/en/latest/
But question here is: How to do this -which package can handle this- for URL mapping instead of host mapping?
Note: django-multitenants mentions "Supports url patterns as well as sub-domains" but not clear how to do this... https://pypi.python.org/pypi/django-multitenants
Upvotes: 2
Views: 1973
Reputation: 1796
Solved with great help from Pythonanywhere support in following way:
Roughly:
Upvotes: 1
Reputation: 5867
From a bit of poking around in django-multitenants
, it looks like it's meant to support URL-based multitenancy using a setting called TENANT_BASE_PATH
However... if you search the codebase of the project on GitHub, the only references to that setting appear in the documentation, not in the code itself. So it may be that django-multitenants
isn't a finished project, but rather a work-in-progress that may have been abandoned (last commit was just 14 days after the initial commit).
Upvotes: 0