如何调试Flask应用程序 [英] How to debug a Flask app

查看:325
本文介绍了如何调试Flask应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是如何在Flask中调试错误的?打印到控制台? Flash消息到页面?还是有一个更强大的选项可以弄清出事情发生了什么?

解决方案

在调试模式下运行应用程序 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆