Everything else including debugging and setting breakpoints in views.py or wherever else works fine, but in template-files, I can’t set breakpoints: when I click left of the line numbers in a template-file, nothing happens, no red dot occurs.
Is anybody here able to set breakpoints in templates? Do you have an idea what’s wrong with my configuration? Thanks!
I am currently using MacOS Version 12.1, Python 3.8.7, Django 3.2.9 and Visual Studio gives the following information:
If Ken’s advice doesn’t help, try disabling any third-party Django extensions in Code. I recall a similar issue solved by disabling one specific extension but I forget which one. Sorry.
Before that, I tried to disable suspect extensions – without success. I had to learn, that – in this case – it wasn’t enough to restart Visual Studio Code, but I had to disable and re-enable the Python extension to get it working properly again.
Now the code in the templates looks a bit stale, but the ability to examine the variables should be worth it, I guess.
The other extension Django Template, mentioned by @speno, has one advantage: the breakpoints can be set as soon as you disable this extension – without dis- and re-enabeling the Python extension and without restart. So you can have both, nice looking source code in templates and setting breakpoints. Well, not simultaneously, but as a workaround it’s okay to disable Django Template temporarily.
Just to add that, this happens due to the file association of the .html files. VS Code does seem to allow debugging only when the file language mode is Html (html) (option from the change language mode). Therefore, there is no need to enable/disable any extension, you just need change the language mode of the file from Django Template to HTML and breakpoints will be enabled.
Hi, you can add in your vscode settings.json file user "debug.allowBreakpointsEverywhere": true,
and you can add breakpoints in django templates without change the language mode.