Skip to main content

call_command

Call the given command, with the given options and args/kwargs.

This is the primary API you should use for calling specific commands.

command_name may be a string or a command object. Using a string is preferred unless the command object is required for further processing or testing.

Some examples: call_command('migrate') call_command('shell', plain=True) call_command('sqlmigrate', 'myapp')

from django.core.management.commands import flush
cmd = flush.Command()
call_command(cmd, verbosity=0, interactive=False)
# Do something with cmd ...
def call_command(
command_name: str | BaseCommand,
*args: Any,
**options: Any
) - > Any

Call the given command, with the given options and args/kwargs. This is the primary API you should use for calling specific commands.

Parameters

NameTypeDescription
command_name`strBaseCommand`
*argsAnyPositional arguments to be passed to the command's argument parser.
**optionsAnyNamed options and flags to configure the command's behavior, such as verbosity or interactive mode.

Returns

TypeDescription
AnyThe result of the command's execution, typically the output of the command's handle() method.