You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

32 lines
1019 B

"""
Domain-based URL Configuration Middleware
This middleware detects the request domain and routes to the appropriate
URLconf (URL configuration) for each site:
- Dovoodi domains → config.urls_dovoodi
- Imam Javad domains → config.urls_imamjavad
"""
class SiteMiddleware:
"""
Middleware to route requests to different URL configurations based on domain.
This allows each domain to have clean /admin/ URLs instead of path-based
differentiation (/imam-javad/admin vs /dovoodi/admin).
"""
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
host = request.get_host()
# Check if the request is from Dovoodi domain
if 'dovodi' in host or 'dovoodi' in host:
request.urlconf = 'config.urls_dovoodi'
# Otherwise, use Imam Javad configuration (default)
else:
request.urlconf = 'config.urls_imamjavad'
return self.get_response(request)