diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 23f04ecd9d..e903509075 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -86,6 +86,10 @@ class BaseHandler: if response is None: raise ValueError, "The view %s.%s didn't return an HttpResponse object." % (callback.__module__, callback.func_name) + # Apply response middleware + for middleware_method in self._response_middleware: + response = middleware_method(request, response) + return response except exceptions.Http404, e: if DEBUG: diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py index eec35ff072..aed8e140ba 100644 --- a/django/core/handlers/modpython.py +++ b/django/core/handlers/modpython.py @@ -144,10 +144,6 @@ class ModPythonHandler(BaseHandler): finally: db.db.close() - # Apply response middleware - for middleware_method in self._response_middleware: - response = middleware_method(request, response) - # Convert our custom HttpResponse object back into the mod_python req. populate_apache_request(response, req) return 0 # mod_python.apache.OK diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index 23204e63a6..8cbb122b5d 100644 --- a/django/core/handlers/wsgi.py +++ b/django/core/handlers/wsgi.py @@ -160,10 +160,6 @@ class WSGIHandler(BaseHandler): finally: db.db.close() - # Apply response middleware - for middleware_method in self._response_middleware: - response = middleware_method(request, response) - try: status_text = STATUS_CODE_TEXT[response.status_code] except KeyError: