24

I've been using Flask for a little while and find I prefer it to Rails in some ways, particularly for being lightweight. However, one area in which Rails is far superior in my opinion is error reporting. There are many times in Flask where I get an error in my browser, but my console shows no error at all (for example, trying to pull non-existant querystring parameters out of request.form produces a 400 Bad Request, but all you see on the console is the incoming request).

Is there any kind of a verbose mode on Flask which will give me detailed information on all of its behavior?

3 Answers 3

7

The debug mode can be enabled via env variable (export FLASK_DEBUG=1) or within the code to allow printing traceback in case of errors as noted below:

app = Flask(__name__)
app.debug = True
3

You probably want to enable debug mode.

4
  • 9
    I've been doing that, but even running with debug=True produces a very anemic amount of information. For most things, the only thing Flask prints to the console are the HTTP requests.
    – limp_chimp
    May 30, 2013 at 19:04
  • 1
    When I use Flask in debug mode, exceptions in my code (like accessing a nonexistent dict key) trigger the debugger, which produces a complete backtrace with full source code and an interactive shell at each stack frame, all in the browser window. If that is anemic, I can't imagine what you might consider rich. Perhaps you ought to post some code so we can get a better idea of what you're seeing.
    – ʇsәɹoɈ
    May 31, 2013 at 4:29
  • 1
    Maybe you need to tweak your config a bit for the exceptions to propagate? flask.pocoo.org/docs/api/#flask.Flask.trap_http_exception
    – ʇsәɹoɈ
    May 31, 2013 at 4:35
  • Using debug mode (along with propagate_exceptions) did nothing for me. Error 500 is still Error 500, with no extra information whatsoever. I don't know what you used to get a backtrace and an interactive shell but it's something more than just debug=True. Nov 3, 2017 at 11:23
2

Error handling is off by default in production mode at the moment and can be set up here: http://flask.pocoo.org/docs/errorhandling/

1
  • 1
    I think he wants to turn off the BadRequestKeyError behavior in development only. May 30, 2013 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.