CodeDrift
V2EX  ›  问与答

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

  •  
  •   CodeDrift · Apr 22, 2015 · 3608 views
    This topic created in 4222 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
    n37r06u3
    Apr 22, 2015
    1
    看log。。。。
    crazyxin1988
    crazyxin1988
    Apr 22, 2015
    2
    看log
    debug
    开源的好处
    问题不是在django的代码里 就是在你的代码里
    当然 99% 在自己的代码里 哈哈
    dalang
    dalang
    Apr 22, 2015
    3
    试试 django-extension,另外可以使用添加 `import pdb; pdb.set_trace()` 来调试
    GG668v26Fd55CP5W
    GG668v26Fd55CP5W
    Apr 22, 2015 via iPhone
    4
    django的debug算是最直观的了
    CodeDrift
    CodeDrift
    OP
    Apr 22, 2015
    5
    @dalang 谢谢 我去看下。

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