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

前端 未结 4 2062
无人及你
无人及你 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:46

    We can also use logging to print data on the console.

    Example:

    import logging
    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/print')
    def printMsg():
        app.logger.warning('testing warning log')
        app.logger.error('testing error log')
        app.logger.info('testing info log')
        return "Check your console"
    
    if __name__ == '__main__':
        app.run(debug=True)
    

提交回复
热议问题