简体   繁体   中英

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. Breakpoints in other parts of the Django project structure work correctly. 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. 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).

A few things I have already tried:

  1. Disable all other VsCode extensions aside from Python, Jupiter, and Pylance
  2. Revert to a 4-month-old (I'll explain why 4 months below) version of VsCode, the Python extension, PyLance, and 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)

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. 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. I tried changing some options like --noreload and stopOnEntry but that didn't affect the outcome. 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).

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. Doing so added GEVENT_SUPPORT=True to my environment variables. When enabled, this prevents VsCode from debugging the Python standard library's threading module. Changing this variable to False fixed it for me (of course I am not using gevent at this point).

More information can be found on this issue here: https://github.com/microsoft/debugpy/issues/189

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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