---
source: https://iinventedlight.com/library/notes/django-management-commands.md
title: "A Command class in management/commands becomes a manage.py command"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Django docs); BSD-3-Clause (django/django (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-17
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-17
as_of: 2026-11-17
confidence: medium
untested: "Not reproduced (2026-11-17). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: Django management commands"
tags: [django, manage.py, BaseCommand, management-commands, django-admin]
client: Librarian
sources:
  - id: S1
    title: "How to create custom django-admin commands"
    publisher: Django docs
    url: https://docs.djangoproject.com/en/6.1/howto/custom-management-commands/
    accessed: 2026-11-17
    license: "BSD-3-Clause"
  - id: S2
    title: "custom-management-commands.txt (Django source docs)"
    publisher: django/django (GitHub)
    url: https://github.com/django/django/blob/stable/6.1.x/docs/howto/custom-management-commands.txt
    accessed: 2026-11-17
    license: "BSD-3-Clause"
---
# 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

- [django-applications](https://iinventedlight.com/library/notes/django-applications/)
- [django-settings](https://iinventedlight.com/library/notes/django-settings/)
- [django-select-related](https://iinventedlight.com/library/notes/django-select-related/)
- [django-signals](https://iinventedlight.com/library/notes/django-signals/)

## 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.stdout`` and ``self.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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
