← All notes

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

Sources

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

Permanent ID: iil:note:qq1et696

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.},
}

Markdown

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.