在venv 环境下如何单步调试 django 项目
- 设置setting.json
点击首选项-> 设置 打开setting.json 文件
{
"python.venvPath": "/Users/apple/python_workspace/venv",
"window.zoomLevel": 1,
"python.pythonPath": "/Users/apple/python_workspace/venv/bin/python3.6",
"editor.renderWhitespace": "all",
"files.exclude": {
"**/.git": false,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/*.pyc":true
},
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_django"
],
"explorer.confirmDragAndDrop": false
}
找到自己设置的venv环境的python地址,按照上面代码所示,修改
venvPath
和python.Path
,完成后重启vscode,
然后 查看-> 命令面板->搜索Select Interpreter
选择刚才设置的Python。
- 配置launch.json
点击调试->添加配置->
{
"name": "Diango",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/manage.py",
"cwd": "${workspaceRoot}",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"env": {},
"envFile": "${workspaceRoot}/../venv",
},