How to print from Flask @app.route to python console

An easy way to do this is by printing to stderr. You can do that like this:

from __future__ import print_function # In python 2.7
import sys

@app.route('/button/')
def button_clicked():
    print('Hello world!', file=sys.stderr)
    return redirect("https://stackoverflow.com/")

Flask will display things printed to stderr in the console. For other ways of printing to stderr, see this stackoverflow post

Leave a Comment