Skip to content

Instantly share code, notes, and snippets.

@victorono
Created September 10, 2014 01:37
Show Gist options
  • Select an option

  • Save victorono/29c34db917890c71a0a6 to your computer and use it in GitHub Desktop.

Select an option

Save victorono/29c34db917890c71a0a6 to your computer and use it in GitHub Desktop.
Detect domain and set id
class SiteDetectionMiddleware:
def process_request(self, request):
settings.SITE_ID = 1
host = request.META.get('HTTP_HOST')
if host:
try:
site = Site.objects.get(domain=host)
settings.SITE_ID = site.id
except Site.DoesNotExist:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment