I have a Django app that will serve diferent websites.
- Each one will have it´s own domain
- Each one will have it´s own sub app with templates and views
- They all share the same backend, models and data
My aproach
As I already have the database with the segmentation info I need to show the desired products in each site and I will have different views for each sub app, I don´t need to add another field in the models.
I think that it would be easier just to detect the request domain in my main app urls.py and rout home url to the desired sub app.
Something like:
# urls.py
if "name1" in request.domain:
urlpatterns += [path('', include('app1.urls'))]
if "name2" in request.domain:
urlpatterns += [path('', include('app2.urls'))]
else:
urlpatterns += [path('', include('app3.urls'))]
Maybe I should make a middleware and set a global variable I can access in urls.py? Can I use this kind of if statements in urls.py?
Django sites
I checked the Django Sites Framework, but if I understand ir well, it´s more focused in segmenting the database in the models, not the templates and views. In any case I don´t really catch how the Sites framework detects the incomming URL and roots the request to each sub app.
Other intents
I searched for more info and this article can brief the different articles about the issue I found.
https://medium.com/crowdbotics/how-to-use-dynamic-subdomains-in-django-dc1cb2cac00b
But still I don´t get how can I achieve what I need. Sounds very logical just to use my aproach and don´t mess with my database. If it´s possible.
Any clues welcome. Thanks in advance!