PyCharm
 
Get PyCharm
You are viewing the documentation for an earlier version of PyCharm.

Part 2. Debugging Django Templates

Last modified: 17 March 2022

Before you start, ensure that Django is specified as the project template language. See section Add Django templates for details.

Note that Django server run/debug configuration is created automatically, and the only thing required is editing it.

In the Django applications, all the functions of the Debug tool window are available, same as for the pure Python scripts. For example, you can step through your application, evaluate expressions, watch variables and more.

  • Stepping through the program The stepping toolbar becomes active, and the stepping buttons are available. For example, click Step over and see that the value of the char variable changes to the next letter of the word world.

    See the Step through the program section for details.

  • Evaluating expressions Press Alt+F8, or, on the Stepping toolbar, click Evaluate expression. In the dialog that opens, type the expression you wish to evaluate, and click Evaluate:

    Evaluate expressions

    See the Evaluate expressions section for details.

  • Watching variables Suppose, you'd like to always keep an eye on a certain variable of a template, say, char. How to do that?

    In the Variable tab, make sure that the watches button is pressed (if this button is pressed, then the watches are visible in the Variables tab), and then click the New debugger watch button. Type the name of the variable of interest, and now your watch is always on top of the Variables tab.

    When you deselect the watches button, the watched variable is shown in the dedicated Watches tab.

    Watching in the debug tool window

    See the Watches for details.

That's it... What has been done here? Let's repeat:

  • You've created a Django project, with a template in it.

  • You've added a breakpoint to this template.

  • You've created the Django server run/debug configuration, and launched it in the debug mode.

  • Having hit the breakpoint, you've learned how to step through your template, evaluate expressions, and add watches.

The next step is also intended for the Professional edition users - this is Debugging JavaScript.

Procedures

Language and Framework-Specific Guidelines