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

前端 未结 4 2060
无人及你
无人及你 2021-01-30 06:14

I would like to simply print a \"hello world\" to the python console after /button is called by the user.

This is my naive approach:

@app.route(\'/button         


        
4条回答
  •  既然无缘
    2021-01-30 06:36

    It seems like you have it worked out, but for others looking for this answer, 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('/')
    

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

提交回复
热议问题