Fixed #21912 -- Improved error message if a view returns None.

Thanks brycenesbitt for the report.
This commit is contained in:
Aaron France 2014-02-15 15:55:50 +01:00 committed by Tim Graham
parent d97bf2e9c8
commit 1150053b99
2 changed files with 6 additions and 5 deletions

View File

@ -128,7 +128,8 @@ class BaseHandler(object):
view_name = callback.__name__ view_name = callback.__name__
else: # CBV else: # CBV
view_name = callback.__class__.__name__ + '.__call__' 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 # If the response supports deferred rendering, apply template
# response middleware and then render the response # response middleware and then render the response

View File

@ -382,7 +382,7 @@ class MiddlewareTests(BaseMiddlewareExceptionTest):
self._add_middleware(middleware) self._add_middleware(middleware)
self._add_middleware(pre_middleware) self._add_middleware(pre_middleware)
self.assert_exceptions_handled('/middleware_exceptions/null_view/', [ 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()) ValueError())
@ -399,7 +399,7 @@ class MiddlewareTests(BaseMiddlewareExceptionTest):
self._add_middleware(middleware) self._add_middleware(middleware)
self._add_middleware(pre_middleware) self._add_middleware(pre_middleware)
self.assert_exceptions_handled('/middleware_exceptions/null_view/', [ 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()) ValueError())
@ -693,7 +693,7 @@ class BadMiddlewareTests(BaseMiddlewareExceptionTest):
self._add_middleware(bad_middleware) self._add_middleware(bad_middleware)
self._add_middleware(pre_middleware) self._add_middleware(pre_middleware)
self.assert_exceptions_handled('/middleware_exceptions/null_view/', [ 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' 'Test Response Exception'
]) ])
@ -710,7 +710,7 @@ class BadMiddlewareTests(BaseMiddlewareExceptionTest):
self._add_middleware(bad_middleware) self._add_middleware(bad_middleware)
self._add_middleware(pre_middleware) self._add_middleware(pre_middleware)
self.assert_exceptions_handled('/middleware_exceptions/null_view/', [ 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()) ValueError())