Skip to content

Instantly share code, notes, and snippets.

@ajamaica
Created February 18, 2012 23:39
Show Gist options
  • Save ajamaica/1861328 to your computer and use it in GitHub Desktop.
Save ajamaica/1861328 to your computer and use it in GitHub Desktop.
SubdominiosMiddleware
from django.conf import settings
import re
class SubdominiosMiddleware:
def process_request(self, request):
request.domain = request.META['HTTP_HOST']
request.subdomain = ''
parts = request.domain.split('.')
if len(parts) == 3 or (re.match("^localhost", parts[-1]) and len(parts) == 2):
request.subdomain = parts[0]
request.domain = '.'.join(parts[1:])
# set the right urlconf
if request.subdomain and request.subdomain != 'www' :
request.urlconf = 'Casher.store.urls' #Ruta de tu URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment