diff --git a/flask.py b/flask.py index 1f0fb7e6..10feaf22 100644 --- a/flask.py +++ b/flask.py @@ -687,7 +687,7 @@ class Flask(object): """Converts the return value from a view function to a real response object that is an instance of :attr:`response_class`. - The following types are allowd for `rv`: + The following types are allowed for `rv`: ======================= =========================================== :attr:`response_class` the object is returned unchanged @@ -703,6 +703,11 @@ class Flask(object): :param rv: the return value from the view function """ + if rv is None: + from warnings import warn + warn(Warning('View function did not return a response'), + stacklevel=2) + return u'' if isinstance(rv, self.response_class): return rv if isinstance(rv, basestring): diff --git a/tests/flask_tests.py b/tests/flask_tests.py index 5f07fbe8..917f4168 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -15,6 +15,7 @@ import sys import flask import unittest import tempfile +import warnings example_path = os.path.join(os.path.dirname(__file__), '..', 'examples') @@ -224,6 +225,19 @@ class BasicFunctionalityTestCase(unittest.TestCase): assert flask.url_for('static', filename='index.html') \ == '/static/index.html' + def test_none_response(self): + warnings.filterwarnings('error', 'View function did not return') + app = flask.Flask(__name__) + @app.route('/') + def test(): + return None + try: + app.test_client().get('/') + except Warning: + pass + else: + assert "Expected warning" + class JSONTestCase(unittest.TestCase):