3đź‘Ť
âś…
You need to have a two different urls files. One for domain and second for subdomains.
- Split domain and subdomain views in two url files. If you have views which works on both e.g. login, create a “common” file and include in both urls.
- You can choose which url you will use, so create a middleware and inspect a host
request.META.get('HTTP_HOST')
. If request comes from subdomain, then simply load appropriated urlsrequest.urlconf = 'path.to_subdomain.urls'
Note:
Be sure that ROOT_URLCONF
in your settings.py point to the “domain’ urls. Also, in your middleware you should inspect does subdomain exists and return 404 if it doesn’t exist.
👤Goran
Source:stackexchange.com