Debug a Flask (Python) web application in Visual Studio Code

后端 未结 8 1910
失恋的感觉
失恋的感觉 2020-12-11 04:28

How do I configure Visual Studio Code to debug a Flask (Python) web application?

For example, when I set the debugger in the view function, it should allow me to step

8条回答
  •  抹茶落季
    2020-12-11 05:01

    We can use the first answer to Linux (Ubuntu) as well with the modifications below.

    In Visual Studio Code, add the configuration for Flask debug. Which you will get from the add button. And it will look like below.

    {
        "name": "Flask",
        "type": "python",
        "request": "launch",
        "stopOnEntry": false,
        "pythonPath": "${config:python.pythonPath}",
        "program": "${workspaceRoot}/app.py", # Your start .py file
        "env": {
            "FLASK_APP": "${workspaceRoot}/app.py" # Your start .py file
        },
        "args": [
            "run"
            // --no-debug and one more line removed.
        ],
        "envFile": "${workspaceFolder}/.env",
        "debugOptions": [
            "RedirectOutput"
        ]
    }
    

    Step 2. Go to menu FilePreferencesSettings, and then click on the workspace settings tab in the top right corner. Insert the following field: "python.pythonPath": "${workspaceRoot}/venv/bin/python2.7", (If your virtual environment is named something other than venv then replace it with the appropriate value.)

提交回复
热议问题