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.
-
If you're trying to debug manage.py commands (those in app/management/commands/ folder), you can use @Kevin's answer, but put in manage.py in the "Script", and the command you want to run in "Script parameters". – RVC Oct 23 '14 at 02:41
-
related: https://stackoverflow.com/a/11725797 – djvg Aug 24 '23 at 12:22
3 Answers
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à!

- 9,924
- 6
- 56
- 69

- 2,779
- 1
- 16
- 10
-
42Emphasis for people like me who apparently can't read properly: the **Host** and **Port** fields have to be cleared, otherwise the custom command will not work! – Henrik Heimbuerger Jul 15 '14 at 17:26
-
Sorry, but what am I supposed to put into "custom run command?" I called mine "simple_chart" but I get "unknown command" when I try to debug. I have a method in views.py called simple_chart that I have placed a break point in. All I want is for the debugger to halt there so I can explore the variables in the local environment. – Frikster Jan 15 '16 at 20:21
-
The run window does not show if I clear the Host and Port fields. – Fish Monitor Mar 14 '16 at 09:18
-
@DirkHaupt you've probably solved it at this point but I found that using underscores threw off commands sometimes. – Caleb_Allen May 13 '16 at 17:13
-
2
-
-
22For those who are struggling: the "custom run command" box should contain only your command. E.g. if you are running `py manage.py cmd` from console, this box will contain simply `cmd`. – texnic Dec 13 '16 at 09:05
-
2@Dejell : you need the professional version of Pycharm for DJANGO support. ( https://www.jetbrains.com/pycharm/features/editions_comparison_matrix.html ) – PeterN Feb 21 '17 at 08:02
-
Also make sure not to have whitespace after the command name - it will wrap it in quotes and not work. – maniexx Jun 19 '18 at 13:13
-
For anyone else having trouble finding it, the Edit Configurations option is found under the Run menu. – GlenVaughan Feb 25 '22 at 18:15
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
.

- 4,155
- 3
- 32
- 53
-
2This is what got it working for me, (pycharm 2016). Put manage.py in script, your django management command in script parameters (together with any django mangement command flags) and change the working directory. – Yunti Apr 29 '16 at 15:16
-
I am explaining using my following custom Django command:
python manage.py execute_algorithm -f input_data.json
Steps to configure Django Command: Step: From Django toolbar go to:
Run > Edit Configurations
Click on the '+' icon at top left, to create new command > select 'Django server' from the drop down.
Fill following details:
Name: any suitable name that you want to give to this config e.g. execute_algorithm_command
Host: Clear the field
Port: It's 8000 by default, clear it.
Custom Run Command: Check this box fist. Provide your command name there. You can get that from
apps/module/management/command/execute_algorithm
. e.g value: execute_algorithm
Additional options: Whatever is there, after you command name. value is: -f input_data.json

- 103
- 1
- 8
-
-
2@miken32 Looking back the first one has everything one needs, but for some reason, I did not get it. This answer accomplishes the same as the first one but uses an example. BTW some of us understand things explained differently. – fang_dejavu Feb 01 '22 at 01:40