[Fixed]-How to configure Visual Studio Code to debug Django app in a virtualenv?

20👍

For me, the following 2 changes worked

  1. Add an absolute path for pythonPath
  2. Use the "--noreload" option while starting the project

Here’s the relevant part of my config

    {
        "name": "Django",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "/Users/xyz/Documents/dev/my_project/my_project_env/bin/python",
        "program": "${workspaceRoot}/manage.py",
        "args": [
            "runserver",
            "0.0.0.0:8080",
            "--noreload"                
        ],
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput",
            "DjangoDebugging"
        ]
    },

6👍

1) Press CTRL + ,
2) Select Workspace Settings
3) Add the following line in the settings file opened.

"python.pythonPath": "path_to_your_env"

You’re done!

4👍

This official tutorial worked in my case.

Just needed to open the "command palette" of VS Code and select my Python Interpreter to the virtual environment:

enter image description here

enter image description here

Full reference: https://code.visualstudio.com/docs/python/tutorial-django#_create-a-project-environment-for-the-django-tutorial

Leave a comment