The signature of BaseCommand.handle is handle(*args, **kwargs). The documentation example only uses the kwargs argument.
Are there cases/ways to define command arguments/options such that they will appear as positional arguments to the handle function?
To answer: "What is
*argsin a Django BaseCommand handle function for?"...The
*argsis a way to define the arguments of thehandle(...)method.As far as I can tell, in the
BaseCommand.handle(...),argsis not connected to command line argument parsing in any way.As an aside, using
*and**is common practice in Python when you don't know how many arguments will be passed to the method. The names (e.g.args,kwargs,optionsare determined by the author of the code, and can be anything.If you want to learn more about
*and**in Python, some places to start:To answer: "Are there cases/ways to define command arguments/options such that they will appear as positional arguments to the handle function?"...
As far as I can tell, no. Assuming you use the
add_arguments(...)method, arguments from the command line will always get placed in theoptionsdict.To answer a question that wasn't asked, but maybe will be useful to readers: How can you get a required positional argument in the
handle(...)method?