Flask Snippets

Snippets are unofficial and unmaintained.

This is an archived view of user-submitted snippets. Despite being hosted on the Flask site, they are not official. No Flask maintainer has curated or checked the snippets for security, correctness, or design.

Triggering the debugger on purpose

Posted by Dag Odenhall on 2010-05-26 @ 15:43 and filed in Utilities

The Flask (Werkzeug) debugger is really good, but it only triggers on exceptions — sometimes it could be useful for debugging behavior that isn't raising anything. In these situations you can simply raise an exception intentionally.

@app.route('/')
def index():
   do_something_wrong()
   raise
   return 'Ohnoes'

This use of raise is actually wrong, which means it… raises an exception. ☺

If you're afraid you might accidentally leave this in the code, here's one that only enters the debugger in debug-mode:

assert app.debug == False

This snippet by Dag Odenhall can be used freely for anything you like. Consider it public domain.

Comments