CodeDrift
V2EX  ›  问与答

求问 django 如何快速确定出错位置

  •  
  •   CodeDrift · Apr 22, 2015 · 3184 views
    This topic created in 4064 days ago, the information mentioned may be changed or developed.

    例如,代码500行。都写在了try里面。输出了错误(print e)。提示数据库没有对应的列,如何快速确定出错位置。菜鸟,还没接触单元测试什么的。如果单元测试可以,求给出具体方法,谢谢!

    一直用print 来卡位置 测试出错位置 。捂脸....

    8 replies    2015-04-22 13:35:45 +08:00
    n37r06u3
        1
    n37r06u3  
       Apr 22, 2015
    看log。。。。
    crazyxin1988
        2
    crazyxin1988  
       Apr 22, 2015
    看log
    debug
    开源的好处
    问题不是在django的代码里 就是在你的代码里
    当然 99% 在自己的代码里 哈哈
    dalang
        3
    dalang  
       Apr 22, 2015
    试试 django-extension,另外可以使用添加 `import pdb; pdb.set_trace()` 来调试
    GG668v26Fd55CP5W
        4
    GG668v26Fd55CP5W  
       Apr 22, 2015 via iPhone
    django的debug算是最直观的了
    CodeDrift
        5
    CodeDrift  
    OP
       Apr 22, 2015
    @dalang 谢谢 我去看下。

    @n37r06u3 有时候加了try 后。。log就抓不到了。。 不过还是谢谢!
    delo
        6
    delo  
       Apr 22, 2015 via iPhone
    有必要都写在try里吗…
    yangtukun1412
        7
    yangtukun1412  
       Apr 22, 2015
    print traceback.format_exc()
    messense
        8
    messense  
       Apr 22, 2015
    import pdb
    pdb.set_trace()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2826 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 109ms · UTC 12:17 · PVG 20:17 · LAX 05:17 · JFK 08:17
    ♥ Do have faith in what you're doing.