skip to Main Content

As the title says. I have a Django 4.1 app, which uses Werkzeug to enable https. I have the following launch.json set up:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "python": "${workspaceFolder}/venv/Scripts/python.exe",
            "program": "${workspaceFolder}\appname\manage.py",
            "args": [
                "runserver_plus",
                "--cert-file",
                "${workspaceFolder}/certs/cert.pem",
                "--key-file",
                "${workspaceFolder}/certs/key.pem"
            ],
            "justMyCode": false,
            "django": true
        }
    ]
}

When I run this through the VSCode debugger it immediately quits in the get_wsgi_application() function with "No module named manage". I tried googling around, but no answer proved to be useful. Any ideas what I am doing wrong?

2

Answers


  1. try this

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Django",
                "type": "python",
                "request": "launch",
                "python": "${workspaceFolder}/venv/Scripts/python.exe",
                "program": "${workspaceFolder}/manage.py",
                "args": [
                    "runserver",
                ],
                "justMyCode": false,
                "django": true
            }
        ]
    }
    
    Login or Signup to reply.
  2. This problem is only specific to VS Code’s debugger and it is happening for wrong path in PYTHONPATH variable. Hence, this problem will not happen if you run it from shell.

    In your case, you need to add a new attribute named env in the launch.json configuration, which will add environment variable. In there you need to update the PYTHONPATH, because manage.py is not in the root folder of the project:

    "configurations": [
            {"env": {
                    "PYTHONPATH": "${workspaceRoot}\appname"
                },
                "name": "Python: Django",
                "type": "python",
                "request": "launch",
                "program": "${workspaceFolder}\appname\manage.py",
                "args": [
                    "runserver_plus"
                ],
                "django": true,
                "justMyCode": false
            }
        ]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search