# Debug Templates with Visual Studio Code

**URL:** <https://forum.djangoproject.com/t/debug-templates-with-visual-studio-code/11141>\
**Category:** Getting Started\
**Created:** [December 21, 2021, 11:25am UTC](https://forum.djangoproject.com/t/debug-templates-with-visual-studio-code/11141 "2021-12-21T11:25:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralfzosel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ralfzosel/32/6584_2.png) [@ralfzosel](https://forum.djangoproject.com/u/ralfzosel)\
**Post date:** [December 21, 2021, 11:25am UTC](https://forum.djangoproject.com/t/debug-templates-with-visual-studio-code/11141/1 "2021-12-21T11:25:26Z")

</div>

The “[Django Tutorial in Visual Studio Code](https://code.visualstudio.com/docs/python/tutorial-django#_use-the-debugger-with-page-templates)” has a chapter “[Use the debugger with page templates](https://code.visualstudio.com/docs/python/tutorial-django#_use-the-debugger-with-page-templates)”. It explains in detail how to set brakepoints in templates, which sounds quite handy. Unfortunately, it doesn’t work for me.

This is my `launch.json` file:

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

```

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:

```auto
Version: 1.63.2
Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
Date: 2021-12-15T09:37:28.172Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Darwin x64 21.2.0

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 21, 2021, 12:48pm UTC](https://forum.djangoproject.com/t/debug-templates-with-visual-studio-code/11141/2 "2021-12-21T12:48:20Z")

</div>

Try adding the `"justMyCode": false` setting directly under the `"django": true` line.

---

<div class="post-metadata">

**Author:** ![speno](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/speno/32/179_2.png) [@speno](https://forum.djangoproject.com/u/speno)\
**Post date:** [December 21, 2021, 12:49pm UTC](https://forum.djangoproject.com/t/debug-templates-with-visual-studio-code/11141/3 "2021-12-21T12:49:03Z")

</div>

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.

Edit: found it! **[vscode-django-template](https://github.com/iambibhas/vscode-django-template)**

> <https://github.com/iambibhas/vscode-django-template/issues/9>
>
> After installing this extension, I cannot add breakpoints in template files any …more. And by that I mean, the breakpoint area left of the lines is just not clickable. In other file types it still works as expected.

---

<div class="post-metadata">

**Author:** ![ralfzosel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ralfzosel/32/6584_2.png) [@ralfzosel](https://forum.djangoproject.com/u/ralfzosel)\
**Post date:** [December 21, 2021, 10:36pm UTC](https://forum.djangoproject.com/t/debug-templates-with-visual-studio-code/11141/4 "2021-12-21T22:36:18Z")

</div>

Thank you all for your advice. I tried everything and in the end, it turned out: the [Django extension](https://marketplace.visualstudio.com/items?itemName=batisteo.vscode-django) was the culprit. The problem [has been known for a while](https://github.com/vscode-django/vscode-django/issues/48).

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](https://marketplace.visualstudio.com/items?itemName=ms-python.python) 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.

---

<div class="post-metadata">

**Author:** ![ralfzosel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ralfzosel/32/6584_2.png) [@ralfzosel](https://forum.djangoproject.com/u/ralfzosel)\
**Post date:** [December 22, 2021, 6:13am UTC](https://forum.djangoproject.com/t/debug-templates-with-visual-studio-code/11141/5 "2021-12-22T06:13:11Z")

</div>

The other extension [Django Template](https://marketplace.visualstudio.com/items?itemName=bibhasdn.django-html), 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.

---

<div class="post-metadata">

**Author:** ![dstav](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@dstav](https://forum.djangoproject.com/u/dstav)\
**Post date:** [January 23, 2022, 9:37am UTC](https://forum.djangoproject.com/t/debug-templates-with-visual-studio-code/11141/6 "2022-01-23T09:37:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![javimp](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/javimp/32/8949_2.png) [@javimp](https://forum.djangoproject.com/u/javimp)\
**Post date:** [June 19, 2022, 9:54am UTC](https://forum.djangoproject.com/t/debug-templates-with-visual-studio-code/11141/7 "2022-06-19T09:54:50Z")

</div>

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.
