如何在 PyCharm 中调试 Django 命令 [英] How to debug Django commands in PyCharm

查看:36
本文介绍了如何在 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,清除HostPort字段,检查 Custom run command 并输入你的命令名称到复选框右侧.
  • 在单独的字段 Additional options 中输入任何额外的命令行参数,而不是附加在运行命令中.
  • 点击确定.
  • Click Edit Configurations....
  • Click the plus sign and choose Django server.
  • Fill in the Name as you please, clear the Host and Port fields, check Custom 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 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆