How to debug Django commands in PyCharm

I know how to run commands with PyCharm (Tools -> Run manage.py Task), but I would like to debug them too, including my commands and third-party application commands.

+47
django pycharm
Jun 17 '13 at 6:48 on
source share
3 answers

You can debug a custom Django admin / management command in PyCharm by creating a custom Django server entry in the Startup / Debug Settings menu:

  • Click Edit Configurations...
  • Click the plus sign and select Django server .
  • Fill in the Name as you like, clear the Host and Port fields, check the Custom run command and enter the name of your command in the right of the check box.
  • Enter any additional command line arguments in a separate Additional options field that is not added to the run command.
  • Click OK.

Now set a breakpoint, select a new configuration from the Startup / Debug Settings menu, and click the Debug button. Et voilà!

+90
Jun 28 '13 at 0:26
source share

Since clearing the host and port will not lead to running the command at all (PyCharm 5), the solution I found is to use the Python launch configuration instead of the Django server . Fill Script your manage.py script file, other parameters in Script Parameters and configure the environment, for example Working directory .

+2
Mar 14 '16 at 9:39
source share

After installing ipdb (pip install ipdb) put these lines in the debug point:

  import ipdb ipdb.set_trace() 

https://pypi.python.org/pypi/ipdb

-6
Jun 17 '13 at 7:21
source share



All Articles