如何调试Flask应用程序 [英] How to debug a Flask app
问题描述
在调试模式下运行应用程序 app.debug = True
或 app.run(debug = True)
或 FLASK_DEBUG = 1烧瓶运行
)将在浏览器中显示一个交互式回溯和控制台。
如果您使用PyCharm,您可以其调试器的优点在于使用断点来逐步执行代码。只需确保关闭Werkzeug的调试器和代码重新加载。运行配置应指向运行 app.run(debug = True,use_debugger = False,use_reloader = False)
的脚本。您可以离开 use_reloader = True
,但是重新加载会杀死调试上下文,您将不得不再次捕获断点。
How are you meant to debug errors in Flask? Print to the console? Flash messages to the page? Or is there a more powerful option available to figure out what's happening when something goes wrong?
Running the app in debug mode (app.debug = True
or app.run(debug=True)
or FLASK_DEBUG=1 flask run
) will show an interactive traceback and console in the browser when there is an error.
If you're using PyCharm you can take advantage of its debugger to step through the code with breakpoints. Just make sure you turn off Werkzeug's debugger and code reloading. The run configuration should point to a script that runs app.run(debug=True, use_debugger=False, use_reloader=False)
. You can leave use_reloader=True
, but a reload will kill the debugging context and you will have to catch a breakpoint again.
这篇关于如何调试Flask应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!