简体   繁体   English

Visual Studio Code Django 调试断点未在视图和模板上触发

[英]Visual Studio Code Django debugging breakpoints not triggered on Views and Templates

I am facing a debugging issue with VsCode where it's failing to trigger any type of breakpoints (standard or log), but specifically on View calls and Templates.我正面临 VsCode 的调试问题,它无法触发任何类型的断点(标准或日志),但特别是在 View 调用和模板上。 Breakpoints in other parts of the Django project structure work correctly. Django 项目结构的其他部分中的断点工作正常。 For example in this code sample:例如在此代码示例中:

class HomeView(TemplateView):
    template_name = "home/home.html"

    def get(self, request, *args, **kwargs):
        return render(request, self.template_name, {})

A breakpoint on template_name = "home/home.html" will be triggered successfully when the Class is constructed.构造 Class 时将成功触发template_name = "home/home.html"上的断点。 However a breakpoint on return render(request, self.template_name, {}) will never trigger (I would expect it to trigger when the user navigates to the URL this class renders).然而, return render(request, self.template_name, {})上的断点永远不会触发(我希望它在用户导航到 class 呈现的 URL 时触发)。

A few things I have already tried:我已经尝试过的几件事:

  1. Disable all other VsCode extensions aside from Python, Jupiter, and Pylance禁用除 Python、Jupiter 和 Pylance 之外的所有其他 VsCode 扩展
  2. Revert to a 4-month-old (I'll explain why 4 months below) version of VsCode, the Python extension, PyLance, and Django恢复到 4 个月大(我将在下面解释为什么 4 个月)版本的 VsCode、Python 扩展、PyLance 和 Django
  3. Creating a function-based view of the above (which also doesn't trigger the breakpoint)创建上述基于函数的视图(也不会触发断点)
  4. Create a brand new Django project (been able to reproduce this on a brand new project, and two other existing projects)创建一个全新的 Django 项目(能够在一个全新的项目和其他两个现有项目上重现此项目)

The 4-month-old timeline was because the last time I was working with Django and debugging Views was about 4 months ago so figured I would try those versions. 4 个月大的时间线是因为我上次使用 Django 并调试 Views 大约是 4 个月前,所以我想我会尝试这些版本。 I am fairly certain this worked last time I attempted this but I may be mistaken.我相当肯定这在我上次尝试时有效,但我可能弄错了。

For reference, I'm using the standard Django launch config.作为参考,我使用的是标准的 Django 启动配置。 I tried changing some options like --noreload and stopOnEntry but that didn't affect the outcome.我尝试更改一些选项,例如--noreloadstopOnEntry ,但这并没有影响结果。 Copying the config file below for reference:复制下面的配置文件以供参考:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}\\manage.py",
            "args": [
                "runserver"
            ],
            "django": true
        }
    ]
}

Furthermore, setting breakpoints in the Templates do not trigger either and setting a breakpoint in a function called by the get method does not trigger (anything post View call basically).此外,在模板中设置断点也不会触发,并且在 get 方法调用的 function 中设置断点不会触发(基本上是 View 调用后的任何内容)。

Everything I can see from the documentation says this should work, and I thought it used to.我从文档中看到的所有内容都表明这应该有效,而且我认为它曾经如此。 What am I missing this time around or has something changed?这次我错过了什么或发生了什么变化?

Finally figured it out.终于想通了。 A couple of weeks ago I installed gevent ( pip install gevent ) for a project.几周前,我为一个项目安装了 gevent ( pip install gevent )。 Doing so added GEVENT_SUPPORT=True to my environment variables.这样做将GEVENT_SUPPORT=True添加到我的环境变量中。 When enabled, this prevents VsCode from debugging the Python standard library's threading module.启用后,这会阻止 VsCode 调试 Python 标准库的线程模块。 Changing this variable to False fixed it for me (of course I am not using gevent at this point).将此变量更改为False为我修复了它(当然我此时没有使用 gevent)。

More information can be found on this issue here: https://github.com/microsoft/debugpy/issues/189可以在此处找到有关此问题的更多信息: https://github.com/microsoft/debugpy/issues/189

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM