flask项目在vscode中启动调试的配置

使用vscode调试flask项目注意事项

setting.json中,配置venv(虚拟环境)路径:

1
2
3
4
5
6
7
8
9
10
{
// "python.pythonPath": "/usr/local/opt/python3/bin/python3.6",
// 以像素为单位控制字号。
"editor.fontSize": 13,
// Whether to lint Python files.
"python.linting.enabled": false,
"python.linting.pylintEnabled": true,
"python.venvPath": "/venv",
"python.pythonPath": "${workspaceFolder}/venv/bin/python",
}

在launch.json配置文件中,主要更改以下配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"name": "Python: Flask (0.11.x or later)",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/venv/bin/flask",
// 以上需根据环境的实际路径修改
"cwd": "${workspaceFolder}",
"env": {
"FLASK_APP": "${workspaceFolder}/run.py",
"LC_ALL": "en_US.utf-8",
"LANG":"en_US.utf-8"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
}