官术网_书友最值得收藏!

The debug mode

The Flask application run method has a debug option, which, when used, runs it in the debug mode:

    app.run(debug=True) 

The debug mode is a special mode, where the built-in debugger takes precedence on any error, and allows you to interact with the app from a browser:

The console in the web-debugger will let you interact with the current app, and inspect variables or execute any Python code that is in the current execution frame.

Flask will even let you configure a third-party debugger. JetBrains's PyCharm (https://www.jetbrains.com/pycharm), for example, is a commercial IDE for Python, which offers a powerful visual debugger that can be set up to run with Flask.

Since the debug mode allows remote code execution, it's a security hazard even though you need to provide a PIN to access the console. In 2015, the Patreon online service got hacked via the Flask debugger. You need to be extremely cautious not to run the debug mode in production. The Bandit security linter ( https://wiki.openstack.org/wiki/Security/Projects/Bandit) tracks Flask applications that are executed with a plain debug flag, and can be used to prevent deploying an application with that flag.

The plain old pdb module is also a good option when you are tracking down a problem by inserting a pdb.set_trace() call in your code.

主站蜘蛛池模板: 新化县| 南木林县| 宜宾市| 瑞丽市| 岐山县| 阳信县| 将乐县| 五莲县| 岳阳县| 东安县| 酒泉市| 芦山县| 漳平市| 稷山县| 静宁县| 秭归县| 新巴尔虎左旗| 英超| 洛川县| 亳州市| 三原县| 九江市| 旬邑县| 驻马店市| 梨树县| 西华县| 固安县| 仙居县| 乐陵市| 儋州市| 施甸县| 富裕县| 古丈县| 定南县| 石城县| 成安县| 阜平县| 太原市| 荆门市| 滨海县| 霍林郭勒市|