Django Templates Debugging with PyCharm

While more new features are introduced to PyCharm 2.0, the older ones are also being developed — namely Django template debugger, which first appeared in version 1.5.

Now I would like to promote it one more time in order to ask for some feedback for a future development or just inform those who didn’t know about it yet.

How to use the template debugger? Very simple! Just place a breakpoint in your template file at a line with any Django tag or expression.
Set a breakpoint in template file

Run Django server in Debug mode (Shift+F9) and make it render the template (e.g. open the page in your browser).

Voilà! The server has been suspended at the breakpoint and you can see all the rendering context in Variables tab.
Debugger has suspended at the breakpoint

If you’d like to see what’s going on you can step over the expressions and tags one after another, evaluate some expressions (Alt+F8), and of course debug console is enabled and works.
Step over and evaluate with debug console

Suffer from exceptions during template rendering? Wanna trace’em out?

Also simple! Enable Django template exception breakpoints in Breakpoint settings page (Ctrl+Shift+F8) and check the Suspend option.
Django template exception breakpoint

If an exception is raised, the debugger stops at the very line, that has caused it.
Suspended at exception breakpoint

And that is still not all.

Also you can set conditions and log messages to breakpoints (like to normal Python breakpoints). In the nearest EAP a new feature is coming: step into a method or filter calls from a template.

And of course all this works for remote debugging as well.

There is a bunch of things in our tracker which are not yet implemented and waiting for their time:

Vote for those you want implemented earlier. Your votes count!

Feel free to let us know your thoughts and ideas or any issues that you have with the debugger.

Develop with pleasure!

This entry was posted in Cool Feature and tagged , , . Bookmark the permalink.

9 Responses to Django Templates Debugging with PyCharm

  1. Greg Wilson says:

    Debugging Django templates is the main reason I use PyCharm. What I’d _really_ like is code coverage for templates: we routinely use it to identify gaps in our testing of models and views, and would like something similar to identify dead code/untested code in templates as well.

  2. Robert says:

    That is indeed slick! Can’t wait to see what else you have up your sleeves.

  3. Pingback: PyCharm: Django Templates Debugging with PyCharm | Python | Syngu

  4. Does it work with GAE templates as well? Wasn’t able to add a breakpoint so far :(

  5. keywind says:

    I just can’t place the breakpoint when I Click the left gutter area at a line of my template html file, the caret did’t appear. I’m using Pycharm 2.5 trial version on Mac OS X Lion 10.7.4

  6. Srikant says:

    I am using Pycharm with license.. The only reason why I bought Pycharm is I can debug templates (compared to Pydev) but I am totally disappointed as It always shows only 3 variables – False, True, None and nothing else.
    I can put breakpoints in django templates and it does stop at breakpoint but it doesn’t show the variables… I did step thru many lines of code but still it doesn’t show variables….Any idea what is going on.

Leave a Reply to Robert Cancel reply

Your email address will not be published. Required fields are marked *