How to configure Visual Studio code to debug a Django application in virtualenv?

I would like to be able to debug a Django application in Visual Studio Code. I have virtualenv, a change has been made to the launch.json file, which looks like this:

{
    "name": "Django",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "pythonPath": "${workspaceRoot}/.venv/bin/python2.7",
    "program": "${workspaceRoot}/mysite/manage.py",
    "args": [
        "runserver"
    ],
    "debugOptions": [
        "WaitOnAbnormalExit",
        "WaitOnNormalExit",
        "DjangoDebugging",
        "RedirectOutput"
    ]
},

put some gaps in the code and run it. Unfortunately, execution does not stop on a line with breakpoints. I tried the same without virtualenv and everything worked perfectly.

Please indicate what I am doing wrong here.

+4
source share
2 answers

Could you solve this problem?

The following 2 changes were made for me

  • Add absolute path for pythonPath
  • "--noreload"

    {
        "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"
        ]
    },
+8

1) CTRL +,
2) " "
3) .

"python.pythonPath": "path_to_your_env"


!

0

Source: https://habr.com/ru/post/1654408/


All Articles