Skip to content

Instantly share code, notes, and snippets.

@gitllermopalafox
Forked from ajamaica/subdominiosmiddleware.py
Last active August 29, 2015 14:10
Show Gist options
  • Save gitllermopalafox/88096217f9b633ad8be1 to your computer and use it in GitHub Desktop.
Save gitllermopalafox/88096217f9b633ad8be1 to your computer and use it in GitHub Desktop.
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