Skip to main content

ManagementUtility

Encapsulate the logic of the django-admin and manage.py utilities.

Attributes

AttributeTypeDescription
argvlist of strings = sys.argv[:]A list of command-line arguments used to determine which subcommand to execute and with what parameters.
prog_namestringThe executable name used in help text and usage messages, typically derived from the script name or set to 'python -m django'.
settings_exceptionException or null = nullStores any exception encountered during Django settings configuration to provide diagnostic feedback in help messages.

Constructor

Signature

def ManagementUtility(
argv: list = None
) - > null

Parameters

NameTypeDescription
argvlist = NoneA 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

NameTypeDescription
commands_onlyboolean = FalseIf True, returns only the sorted list of command names instead of the full usage text.

Returns

TypeDescription
stringThe 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

NameTypeDescription
subcommandstringThe name of the subcommand to retrieve, such as 'migrate' or 'runserver'.

Returns

TypeDescription
[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

TypeDescription
nullThis 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

TypeDescription
nullNo value is returned as this method typically delegates execution to a subcommand or exits the process.