Skip to content

Instantly share code, notes, and snippets.

@hersonls
Created September 11, 2012 02:35
Show Gist options
  • Save hersonls/3695520 to your computer and use it in GitHub Desktop.
Save hersonls/3695520 to your computer and use it in GitHub Desktop.
Middleware for django-subdomains
class SubdomainURLRoutingMiddleware(SubdomainMiddleware):
def process_request(self, request):
super(SubdomainURLRoutingMiddleware, self).process_request(request)
subdomain = getattr(request, 'subdomain', False)
if subdomain is not False and subdomain not in settings.SUBDOMAIN_BLACKLIST:
# Here is the trick. I will put at the first rule the users url
# set at the settings, this way, the first page will be the
# user page matched with subdomain.
request.urlconf = settings.SUBDOMAIN_URL_ROUTER
# Continue processing the request as normal.
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment