I am trying to write a custom control command in django as shown below -
class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('delay', type=int) def handle(self, *args, **options): delay = options.get('delay', None) print delay
Now when I run python manage.py mycommand 12
, it prints 12 on the console. What well.
Now, if I try to run python manage.py mycommand
, then I want the command to print 21 on the console by default. But it gives me something like this -
usage: manage.py mycommand [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] delay
So, how do I make the argument to the command “not required” and accept the default value if no value is specified?
source share