1 from django.http import HttpResponse
2 from django.utils.decorators import decorator_from_middleware
3 from philo.contrib.penfield.exceptions import HttpNotAcceptable
6 class HttpNotAcceptableMiddleware(object):
7 """Middleware to catch HttpNotAcceptable errors and return an Http406 response.
9 def process_exception(self, request, exception):
10 if isinstance(exception, HttpNotAcceptable):
11 return HttpResponse(status=406)
14 http_not_acceptable = decorator_from_middleware(HttpNotAcceptableMiddleware)