ManagementUtility
Encapsulate the logic of the django-admin and manage.py utilities.
Attributes
| Attribute | Type | Description |
|---|---|---|
| argv | list of strings = sys.argv[:] | A list of command-line arguments used to determine which subcommand to execute and with what parameters. |
| prog_name | string | The executable name used in help text and usage messages, typically derived from the script name or set to 'python -m django'. |
| settings_exception | Exception or null = null | Stores any exception encountered during Django settings configuration to provide diagnostic feedback in help messages. |
Constructor
Signature
def ManagementUtility(
argv: list = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| argv | list = None | A list of command-line arguments. If None, it defaults to sys.argv. |
Methods
main_help_text()
@classmethod
def main_help_text(
commands_only: boolean = False
) - > string
Return the script's main help text, as a string.
Parameters
| Name | Type | Description |
|---|---|---|
| commands_only | boolean = False | If True, returns only the sorted list of command names instead of the full usage text. |
Returns
| Type | Description |
|---|---|
string | The formatted help message containing usage instructions and a list of available subcommands. |
fetch_command()
@classmethod
def fetch_command(
subcommand: string
) - > [BaseCommand](base/basecommand.md?sid=django_core_management_base_basecommand)
Try to fetch the given subcommand, printing a message with the appropriate command called from the command line (usually "django-admin" or "manage.py") if it can't be found.
Parameters
| Name | Type | Description |
|---|---|---|
| subcommand | string | The name of the subcommand to retrieve, such as 'migrate' or 'runserver'. |
Returns
| Type | Description |
|---|---|
[BaseCommand](base/basecommand.md?sid=django_core_management_base_basecommand) | The command class or instance corresponding to the requested subcommand name. |
autocomplete()
@classmethod
def autocomplete() - > null
Output completion suggestions for BASH.
Returns
| Type | Description |
|---|---|
null | This method prints suggestions directly to stdout and terminates the process with sys.exit(0). |
execute()
@classmethod
def execute() - > null
Given the command-line arguments, figure out which subcommand is being run, create a parser appropriate to that command, and run it.
Returns
| Type | Description |
|---|---|
null | No value is returned as this method typically delegates execution to a subcommand or exits the process. |