如何使用VS Code调试Django自定义管理命令 [英] How to debug Django custom management command using VS Code
问题描述
我正在尝试使用Visual Studio代码调试自定义管理命令。
I am trying to debug a custom management command using Visual Studio Code.
为此,我已经阅读了有关使用Python和Django的官方VS Code教程,并且我已经按照这些教程进行调试。
For this I have gone through the official VS Code tutorials for working with Python and Django, and I have managed to get debugging to work while following these tutorials.
VS代码Python教程 /
VS Code Django教程
问题在于,对于Python脚本(无Django),调试器可以正常运行,因为我运行了特定文件(按f5键)文件的标签页打开时。 Django调试有效,因为VS Code知道何时浏览器请求导致我的Django应用达到我在VS Code中输入的断点。
The problem is that for a Python script (no Django), the debugger works because I run a specific file (by pressing f5) while the file's tab is open. Django debugging works because VS Code knows when a browser request causes my Django app to hit a break-point I entered in VS Code.
但是自定义管理命令的运行方式不同。为此,我在控制台中键入以下内容:
But a custom management command is run differently. For this I type the following in the console:
python manage.py name_of_management_command
如何在VS Code中调试它?
How do I debug this in VS Code?
推荐答案
在编写此问题时我想到了
While writing this question I came up with a solution myself.
在VS Code launch.json
文件中(其中包含VS Code Django的设置)调试器)默认包含以下条目:
In the VS Code launch.json
file (which contains the settings for the VS Code Django debugger) contains the following entry, by default:
args:[ runserver, --noreload, --nothreading ]
我将其更改为:
args:[ name_of_management_command]
然后启动调试器(按f5键),我正在调试自定义管理命令
Then start the debugger (press f5), and I am debugging my custom management command
这篇关于如何使用VS Code调试Django自定义管理命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!