From 1150053b994a6de665db51a18a07b992bd6714f1 Mon Sep 17 00:00:00 2001 From: Aaron France Date: Sat, 15 Feb 2014 15:55:50 +0100 Subject: [PATCH] Fixed #21912 -- Improved error message if a view returns None. Thanks brycenesbitt for the report. --- django/core/handlers/base.py | 3 ++- tests/middleware_exceptions/tests.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 3986257660..5d6b36439b 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -128,7 +128,8 @@ class BaseHandler(object): view_name = callback.__name__ else: # CBV view_name = callback.__class__.__name__ + '.__call__' - raise ValueError("The view %s.%s didn't return an HttpResponse object." % (callback.__module__, view_name)) + raise ValueError("The view %s.%s didn't return an HttpResponse object. It returned None instead." + % (callback.__module__, view_name)) # If the response supports deferred rendering, apply template # response middleware and then render the response diff --git a/tests/middleware_exceptions/tests.py b/tests/middleware_exceptions/tests.py index b11986d4d0..406f0f8fea 100644 --- a/tests/middleware_exceptions/tests.py +++ b/tests/middleware_exceptions/tests.py @@ -382,7 +382,7 @@ class MiddlewareTests(BaseMiddlewareExceptionTest): self._add_middleware(middleware) self._add_middleware(pre_middleware) self.assert_exceptions_handled('/middleware_exceptions/null_view/', [ - "The view middleware_exceptions.views.null_view didn't return an HttpResponse object.", + "The view middleware_exceptions.views.null_view didn't return an HttpResponse object. It returned None instead.", ], ValueError()) @@ -399,7 +399,7 @@ class MiddlewareTests(BaseMiddlewareExceptionTest): self._add_middleware(middleware) self._add_middleware(pre_middleware) self.assert_exceptions_handled('/middleware_exceptions/null_view/', [ - "The view middleware_exceptions.views.null_view didn't return an HttpResponse object." + "The view middleware_exceptions.views.null_view didn't return an HttpResponse object. It returned None instead." ], ValueError()) @@ -693,7 +693,7 @@ class BadMiddlewareTests(BaseMiddlewareExceptionTest): self._add_middleware(bad_middleware) self._add_middleware(pre_middleware) self.assert_exceptions_handled('/middleware_exceptions/null_view/', [ - "The view middleware_exceptions.views.null_view didn't return an HttpResponse object.", + "The view middleware_exceptions.views.null_view didn't return an HttpResponse object. It returned None instead.", 'Test Response Exception' ]) @@ -710,7 +710,7 @@ class BadMiddlewareTests(BaseMiddlewareExceptionTest): self._add_middleware(bad_middleware) self._add_middleware(pre_middleware) self.assert_exceptions_handled('/middleware_exceptions/null_view/', [ - "The view middleware_exceptions.views.null_view didn't return an HttpResponse object." + "The view middleware_exceptions.views.null_view didn't return an HttpResponse object. It returned None instead." ], ValueError())