diff options
Diffstat (limited to 'django/utils/decorators.py')
-rw-r--r-- | django/utils/decorators.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/django/utils/decorators.py b/django/utils/decorators.py index ee169ec7cc..22f33a76a4 100644 --- a/django/utils/decorators.py +++ b/django/utils/decorators.py @@ -95,10 +95,17 @@ def make_middleware_decorator(middleware_class): if result is not None: return result raise - if hasattr(middleware, 'process_response'): - result = middleware.process_response(request, response) - if result is not None: - return result + if hasattr(response, 'render') and callable(response.render): + if hasattr(middleware, 'process_template_response'): + response = middleware.process_template_response(request, response) + # Defer running of process_response until after the template + # has been rendered: + if hasattr(middleware, 'process_response'): + callback = lambda response: middleware.process_response(request, response) + response.add_post_render_callback(callback) + else: + if hasattr(middleware, 'process_response'): + return middleware.process_response(request, response) return response return _wrapped_view return _decorator |