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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can debug a custom Django admin/management command in PyCharm by creating a custom Django server entry on the Run/Debug Configuration menu:
- 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à!
回答2:
Since clearing Host and Port will not make the command run at all (PyCharm 5), the solution I found is to use a Python run configuration instead of a Django server. Fill Script
with your manage.py script, other parameters in Script Parameters
, and adjust your environment such as Working directory
.
回答3:
After installing ipdb (pip install ipdb) put those lines to debug point:
import ipdb
ipdb.set_trace()
https://pypi.python.org/pypi/ipdb