Created
December 29, 2011 21:31
-
-
Save dfalk/1536295 to your computer and use it in GitHub Desktop.
django subdomains
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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