trent fernandez
trent fernandez

Reputation: 339

How to run debug Django app in Visual Studio Code?

launch.json

            "name": "Django",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config.python.pythonPath}",
            "program": "${workspaceRoot}/manage.py",
            "cwd": "${workspaceRoot}",
            "args": [
                "runserver",
                "--noreload"
            ],
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput",
                "DjangoDebugging"
            ]

In the browser http://localhost:8000/login I have a login page allow user input username and password to login. I put a break points in the code of def login in views.py and run debug but the execution is not stopped on the line with break points. Now I want to allow user input user name and password then they click on button and it will jump to break points def login in views.py. How can I do that?

Upvotes: 5

Views: 5486

Answers (1)

Wayne Johnston
Wayne Johnston

Reputation: 658

Here are instructions for Visual Studio Code version 1.14.2. Older versions may work a bit different.

  • Open your project folder in VS Code
  • Click Debug icon (or press Ctrl + Shift + D)
  • From the drop-down list at the top of the debug pane, select Django
  • Click the Start Debugging button (or press F5)

VS Code will open manage.py and start execution. There should be a debugger tool pallet at the top of the IDE with buttons to step, continue, etc. Breakpoints are set by clicking in the code window to the left of the line number. Django Debugging

I have these VS Code extensions installed (in case it matters).

  • MagicPython 1.0.11
  • Python 0.6.9
  • Python for VS Code 0.2.3

Upvotes: 7

Related Questions