[英]How to configure Visual Studio Code to debug Django app in a virtualenv?
I would like to have possibility to do a debugging of Django application in Visual Studio Code.我想有可能在 Visual Studio Code 中调试 Django 应用程序。 I have a virtualenv, made a change in launch.json file that look like this:我有一个 virtualenv,在launch.json文件中进行了如下更改:
{
"name": "Django",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${workspaceRoot}/.venv/bin/python2.7",
"program": "${workspaceRoot}/mysite/manage.py",
"args": [
"runserver"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"DjangoDebugging",
"RedirectOutput"
]
},
put several break points in the code and run it.在代码中放置几个断点并运行它。 Unfortunately, the execution is not stopped on the line with break points.不幸的是,执行并没有在有断点的线上停止。 I tried the same without virtualenv and everything worked perfectly.我在没有 virtualenv 的情况下尝试了相同的方法,并且一切正常。
Please, point out what I am doing wrong here.请指出我在这里做错了什么。
For me, the following 2 changes worked对我来说,以下 2 个更改有效
"--noreload"
option while starting the project启动项目时使用"--noreload"
选项Here's the relevant part of my config这是我的配置的相关部分
{
"name": "Django",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "/Users/xyz/Documents/dev/my_project/my_project_env/bin/python",
"program": "${workspaceRoot}/manage.py",
"args": [
"runserver",
"0.0.0.0:8080",
"--noreload"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput",
"DjangoDebugging"
]
},
1) Press CTRL + , 1) 按 CTRL + ,
2) Select Workspace Settings 2) 选择工作区设置
3) Add the following line in the settings file opened. 3) 在打开的设置文件中添加以下行。
"python.pythonPath": "path_to_your_env"
You're done!你完成了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.