How to debug Django commands in PyCharm(如何在 PyCharm 中调试 Django 命令)
问题描述
我知道如何使用 PyCharm 运行命令(工具 -> 运行 manage.py 任务),但我也想调试它们,包括我的命令和第三方应用程序的命令.
I know how to run commands with PyCharm (Tools -> Run manage.py Task), but I would like to debug them also, including my commands and third party app's commands.
推荐答案
您可以通过在运行/调试配置菜单上创建自定义 Django 服务器条目来调试 PyCharm 中的自定义 Django 管理/管理命令:
You can debug a custom Django admin/management command in PyCharm by creating a custom Django server entry on the Run/Debug Configuration menu:
- 点击
编辑配置...
. - 单击加号并选择
Django 服务器
. - 随意填写
Name
,清除Host
和Port
字段,检查Custom run command
并输入你的命令名称到复选框右侧. - 在单独的字段
Additional options
中输入任何额外的命令行参数,而不是附加在运行命令中. - 点击确定.
- Click
Edit Configurations...
. - Click the plus sign and choose
Django server
. - Fill in the
Name
as you please, clear theHost
andPort
fields, checkCustom run command
and enter the name of your command to the right of the checkbox. - Enter any extra command-line arguments into the separate field
Additional options
, not appended in the run command. - Click OK.
现在设置一个断点,从运行/调试配置"菜单中选择您的新配置,然后单击调试"按钮.等等!
Now set a breakpoint, choose your new configuration from the Run/Debug Configuration menu and click the Debug button. Et voilà!
这篇关于如何在 PyCharm 中调试 Django 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!