My middleware is :
import urlparse
from django.contrib.sites.models import Site
from django.http import Http404
class GetSubdomainMiddleware:
def process_request(self, request):
site = Site.objects.filter(domain__exact = request.META['HTTP_HOST'])
if site:
bits = urlparse.urlsplit(request.META['HTTP_HOST'])[2].split('.')
request.subdomain = bits[0]
else:
raise Http404
--
Mirat Can Bayrak <miratca...@gmail.com>
> > Right now there is a bug in django's middleware where it doesn't
> > correct catch exceptions: http://code.djangoproject.com/ticket/6094.
> than... what should i do?
Don't raise an exception. A 404 exception is eventually turned into an
HttpResponse with the appropriate status code, so construct one manually
and return that from the middleware. Once you return a response, no
further processing happens (for request middleware). That's one of the
major points about middleware.
Regards,
Malcolm