Django Subdomains to do advanced things

class SimpleSubdomainMiddleware:
def process_request(self, request):
host = request.META.get('HTTP_HOST', '')
host = host.replace('www.', '').split('.')
if len(host) > 2:
request.subdomain = ''.join(host[:-2])
else:
request.subdomain = None
MIDDLEWARE_CLASSES += ( 'path_to_your_file.SimpleSubdomainMiddleware', )
127.0.0.1    abc.com
def login_page(request):
if get_merchant(request.subdomain):
render page of the get_merchant
else:
render generic page or redirect as you wish

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store