I want to find a custom command in a project with many apps, how to get a list of all commands from all apps?
Asked
Active
Viewed 2,407 times
3
-
3Just use `python3 manage.py`. This will list all possible commands. – Willem Van Onsem Mar 28 '22 at 14:02
-
Indeed! I was so sure, that only built-in commands would be listed – Sashko Lykhenko Mar 28 '22 at 14:08
-
1well to some extent, there are no "builtin" commands: Django uses apps as well, so the `auth` app for example exports commands to create users. These are also defines, just like the ones you create yourself. – Willem Van Onsem Mar 28 '22 at 14:34
2 Answers
7
This command will list all the custom or existing command of all installed apps:
python manage.py help

sankalp
- 376
- 3
- 6
0
You can also load django commands using a django module.
To get a list of all custom Django commands in a project, you can use the from django.core.management import get_commands
. This get_commands
function returns a dictionary of all available commands and their associated applications from the running application.
Here is an example of how you can use this function to display all commands and their associated applications:
from django.core.management import get_commands
commands = get_commands()
print([command for command in commands.items()])
#sample output
$ [('check', 'django.core'),
('compilemessages', 'django.core'),
('createcachetable', 'django.core'),
('dbshell', 'django.core'),
('diffsettings', 'django.core'),
('dumpdata', 'django.core'),
('flush', 'django.core'),
('inspectdb', 'django.core'),
('loaddata', 'django.core'),
('makemessages', 'commands'),
('makemigrations', 'django_migration_linter'),
('migrate', 'django.core'),
('runserver', 'django.contrib.staticfiles'),
('sendtestemail', 'django.core'),
('shell', 'django.core'),
]
If you want to display only the commands for a specific application, you can filter the results of get_commands() using the following code:
[command for command in commands.items() if command[1] == 'app_name']
Replace 'app_name' with the name of the application you want to display the commands for.

Lazaro Fernandes Lima Suleiman
- 1,772
- 18
- 30