python - 使用pycharm调试,如何在不进入django库的情况下进入项目

标签 python django debugging pycharm

想想这个场景:

我调试我的 Django 项目并单步执行代码(进出)。调试器有时会进入 Django 库或其他外部库。

有谁知道如何防止调试器输入外部代码?或者至少是一个“大”步骤,让调试器返回到项目代码?

最佳答案

Does anyone know how to prevent the debugger from entering external code?

是的,德米特里·特罗菲莫夫 knows ;

(...) add modules you don't want to trace to the dict DONT_TRACE in <pycharm-distr>/helpers/pydev/pydevd.py
That is a hacky solution (...)

如果你希望这个功能不那么hacky,你可以通过访问问题对其进行投票
PY-9101 Implement "Do not step into the classes" option for Python debugger


使用pdb的人可能有兴趣知道pdb中有这样的特性;

从 Python 3.1 开始,Pdb类有一个名为 skip 的新参数-

class pdb.Pdb(completekey='tab', stdin=None, stdout=None, skip=None, nosigint=False)

The skip argument, if given, must be an iterable of glob-style module name patterns. The debugger will not step into frames that originate in a module that matches one of these patterns. 1

1 Whether a frame is considered to originate in a certain module is determined by the __name__ in the frame globals.

文档中给出的示例显示了如何跳过 Django 的包 -

import pdb; pdb.Pdb(skip=['django.*']).set_trace()

关于python - 使用pycharm调试,如何在不进入django库的情况下进入项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15164565/

相关文章:

javascript - Django 表单操作参数中 PK 的替代方案

c - 在 C 中调用函数时出现段错误

python - 完全独立地从python脚本重启wifi接口(interface)

python - 缺少一个约束的约束满足问题

python - 如何在 django 模板中从外部 url 插入 html 代码?

Django 2.2 + UUID 作为 ID + 默认值

python - 如何将 NumPy 数组与 ctypes 一起使用?

python 暂停 pexpect.spawn 及其使用的设备

debugging - 如何在 Geany 中使用 GDB 插件?

c++ - Visual Studio C++ 2015 Update 3 中的 abs(complex) 出现奇怪问题