Sentry Answers>Flask>

ValueError: View Function Did Not Return a Response

ValueError: View Function Did Not Return a Response

Armin Ronacher

The ProblemJump To Solution

Click to Copy
Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1478, in full_dispatch_request response = self.make_response(rv) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response raise ValueError('View function did not return a response') ValueError: View function did not return a response

The Solution

All Flask views must return a value, usually a Response object. If the flask view throwing the error accepts GET and POST methods, check if you are neglecting return a value for one of the cases.

Click to Copy
@app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': model.save() # Failure to return a redirect or render_template else: return render_template('index.html')

Further Reading

If you’re looking to get a deeper understanding of how Flask application monitoring works, take a look at the following articles:

  • SentryFlask Error Monitoring
  • Syntax.fmListen to the Syntax Podcast
  • Community SeriesIdentify, Trace, and Fix Endpoint Regression Issues
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Considered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.