A Command class in management/commands becomes a manage.py command
Answer: An app can add its own manage.py actions. Put a Python module in the app's management/commands/ directory. Django registers a command for each module whose name does not start with an underscore. The module must define a Command class that extends BaseCommand or one of its subclasses.
handle and arguments
Implement the handle method for the work. Custom options can be added in the add_arguments method. When you wish to provide console output, write to self.stdout and self.stderr, instead of printing to stdout and stderr directly. If the user referenced any nonexistent polls, a CommandError is raised.
The command will be made available to any project that includes the application in INSTALLED_APPS. The new custom command can be called using python manage.py and the command name.
Overriding built-in commands
Django first registers built-in commands, then looks through INSTALLED_APPS in reverse. If two apps register the same command name, the one found later during that reverse search overrides the earlier registration. To override a command, use the same name and put that app before the overridden command's app in INSTALLED_APPS.
See also
Claims
- id: C1 claim: Apps register custom actions with manage.py. source: S1 evidence: "Applications can register their own actions with manage.py"
- id: C2 claim: Modules in management/commands become commands unless the name starts with an underscore. source: S1 evidence: "whose name doesn't begin with an underscore"
- id: C3 claim: The module must define a Command class that extends BaseCommand. source: S2 evidence: "it must define a class"
- id: C4 claim: Write command output to self.stdout and self.stderr. source: S2 evidence: "write to `
self.stdoutandself.stderr`"
Sources
- [S1] How to create custom django-admin commands. Django docs. https://docs.djangoproject.com/en/6.1/howto/custom-management-commands/ . License: BSD-3-Clause. Accessed 2026-11-17.
- [S2] custom-management-commands.txt (Django source docs). django/django (GitHub). https://github.com/django/django/blob/stable/6.1.x/docs/howto/custom-management-commands.txt . License: BSD-3-Clause. Accessed 2026-11-17.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Django docs, How to create custom django-admin commands, BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright (c) Django Software Foundation and individual contributors; django/django (GitHub), custom-management-commands.txt (Django source docs), BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright (c) Django Software Foundation and individual contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Django docs, How to create custom django-admin commands, BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright (c) Django Software Foundation and individual contributors; django/django (GitHub), custom-management-commands.txt (Django source docs), BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright (c) Django Software Foundation and individual contributors.
Cite this
iinventedlight. 2026. "A Command class in management/commands becomes a manage.py command." iinventedlight Library, iil:note:qq1et696, version of 2026-11-17. https://iinventedlight.com/library/notes/django-management-commands/. License: CC-BY-4.0.
@misc{iil_note_qq1et696,
author = {{iinventedlight}},
title = {{A Command class in management/commands becomes a manage.py command}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-17},
url = {https://iinventedlight.com/library/notes/django-management-commands/},
note = {Permanent ID iil:note:qq1et696. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/django-management-commands.md.