Debug Django Project with Visual Studio Code (VSCode)¶
In order to debug Django project, we need to first create a Visual Studio Code (VSCode) run configuration.
Method 1: Create Run Configuration¶
# From the VSCode menu select # Select Python as debugger # Select Django as Debug configuration # Configure the path to your project’s manage.py, e.g. ${workspaceFolder}elearnmanage.py
VS Code creates a new Run Configuration for your Django project and opens the lanuch.json file. You can close it.
Method 2: Create launch.json File¶
In the .vscode directory create or update launch.json to include run configuration for your Django app:
1{
2 // Use IntelliSense to learn about possible attributes.
3 // Hover to view descriptions of existing attributes.
4 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 "version": "0.2.0",
6 "configurations": [
7 {
8 "name": "Python: Django",
9 "type": "python",
10 "request": "launch",
11 "program": "${workspaceFolder}\\elearn\\manage.py",
12 "args": [
13 "runserver"
14 ],
15 "django": true,
16 "justMyCode": true
17 }
18 ]
19}
Running Django Development Server in Debug Mode¶
Open the Run and Debug sidebar (Ctrl-Shift-d). Press the green arrow button to start debugging (or press F5).
Happy debugging!
Shortcut |
Action |
|---|---|
F6 |
Pause |
F5 |
Start/Continue |
F9 |
Toggle Breakpoint |
F10 |
Step Over |
F11 |
Step Into |
Shift-F11 |
Step Out |
Ctrl-Shift-F5 |
Restart |
Shift-F5 |
Stop |