Skip to content

Instantly share code, notes, and snippets.

@dfalk
Created December 29, 2011 21:31
Show Gist options
  • Save dfalk/1536295 to your computer and use it in GitHub Desktop.
Save dfalk/1536295 to your computer and use it in GitHub Desktop.
django subdomains
class SubdomainMiddleware:
""" Make the subdomain publicly available to classes """
def process_request(self, request):
domain_parts = request.get_host().split('.')
if (len(domain_parts) > 2):
subdomain = domain_parts[0]
if (subdomain.lower() == 'www'):
subdomain = None
domain = '.'.join(domain_parts[1:])
else:
subdomain = None
domain = request.get_host()
request.subdomain = subdomain
request.domain = domain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment