Flask1.0.2系列(八) 调试应用程序错误

英文原文地址:http://flask.pocoo.org/docs/1.0/errorhandling/#debugging-application-errors

若有翻译错误或者不尽人意之处,请指出,谢谢~


        对生产应用程序而言,使用日志和通知配置你的应用程序的相关描述见上一章节。这一章节我们讲述,调试部署配置和深入挖掘Python完整的调试器的要点。


1. 当有疑问时,手动运行之

        你是否在配置生产应用程序时遇到过问题?如果你在shell访问你的主机,你可以在shell中手动部署环境来验证你的应用程序是可运行的。务必要确保在与部署环境相同的账户下运行,以解决权限带来的问题。你可以在你的生产主机上使用Flask内置的开发服务(debug=True),这对于捕获配置问题是很有帮助的,但是你一定要确定这是在可控的环境中临时完成这些操作的。在生产系统中一定不能使用debug=True的模式运行。


2. 使用调试器

        为了追踪代码的执行过程,Flask提供了一个可立即使用的调试器(参见快速入门中的调试模式一节)。如果你想要使用其他的Python调试器,那需要注意的是调试器之间的相互干扰。为了使用你喜欢的调试器,你不得不设置一些选项:

        ● debug - 是否能启用调试模式和捕获异常。

        ● use_debugger - 是否能使用Flask内置的调试器。

        ● use_reloader - 是否能在异常情况下重新加载和分叉进程。

        debug必须为True(必须捕获异常)的情况下,其他两项的值才有意义。

        如果你使用的是Aptana/Eclipse进行调试,那么你需要将use_debugger和use_reloader设置为False。

        配置中一个可能有用的模式是,设置如下行在你的config.yaml文件中(当然,你需要酌情为你的应用程序更改区块):

FLASK:
    DEBUG: True
    DEBUG_WITH_APTANA: True

        然后在你的应用程序进入点(main.py),你需要添加如下内容:

if __name__ == "__main__":
    # To allow aptana to receive errors, set use_debugger=False
    app = create_app(config="config.yaml")

    if app.debug: use_debugger = True
    try:
        # Disable Flask's debugger if external debugger is requested
        use_debugger = not(app.config.get('DEBUG_WITH_APTANA'))
    except:
        pass
    app.run(use_debugger=use_debugger, debug=app.debug,
            use_reloader=use_debugger, host='0.0.0.0')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
拯救者15ISK 解锁nvme pcie3.0w 使速度可以到达2300MB/s -? or -h Show this help. -fea Checking whether BIOS support all functions of tool. -r Dump ROM image to file. -a Auto Reset. -l Load Default. -c Load Custom Setting. -gs [-all] Generate setup utility setting to file. (-all: optional , include suppress and grayout setting) -ss Modify setup variable with specified file. -ms -fi -op Modify a setup utility setting. -gd Read image file, and generate setup utility default setting to file. -sd Modify setup utility default setting with specified file on image file. -gstr -s|-b Read image file, and generate setup(-s) or setup browser(-b) string setting. -sstr -s|-b Modify setup or setup browser strings with specified file. -gv Generate variable information to file. -sv Modify variable with specified file. -re -vn -vg Remove a variable by name or GUID. -gi Read image file, and generate variable information to file. -si Modify variable with specified file on image file. -gk Generate BIOS Hotkey setting to file. -mcl List Multi-Config information. -mcl -f|-k Dump the specified config setting to file. -mca -f|-k Add an new config setting with specified file. -mcm -f|-k Modify config setting with specified file. -mcd -f|-k Delete the specified config setting. -lmc [BIOS] -f|-k Load the specified config setting from Multi-Config.(BIOS: optional, it use on Full type to set default setting from BIOS) -i Operation on image. (for Multi-Config command) -out Save as an new ImageFile.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值