Ticket #4438: middleware.py
File middleware.py, 521 bytes (added by , 17 years ago) |
---|
Line | |
---|---|
1 | from django.conf import settings |
2 | from django.contrib.sites.models import Site |
3 | |
4 | """ |
5 | Site-related Middleware |
6 | """ |
7 | |
8 | class SetSiteFromHost: |
9 | """ |
10 | Change the settings.SITE_ID to match the request.META['HTTP_HOST'] |
11 | """ |
12 | |
13 | def process_request(self, request): |
14 | try: |
15 | site = Site.objects.get(domain=request.META['HTTP_HOST']) |
16 | except Site.DoesNotExist: |
17 | # Keep existing setting |
18 | return |
19 | settings.SITE_ID = site.id |
20 | |
21 | # vim: ai ts=4 sts=4 et sw=4 |