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
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 File → Preferences → Settings, 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.)