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:
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