There is a manager-team that I call

manage.py commandname xy 

where x and y are the arguments to be used internally.

I need to pass some arguments that I will pull from * args:

 from django.core.management.base import BaseCommand class Command(BaseCommand): [...] def handle(self, *args, **options): [...] var1 = args[0] var2 = args[1] 

How can I make them pass them by name ?:

 manage.py commandname -otp2 x -opt1 y 

And how then to address them in function? How to make them mandatory and optional?

I guess that there is a simple solution, but I can’t correctly put the question to Google.

    1 answer 1

    The django documentation describes everything with examples:

     from optparse import make_option class Command(BaseCommand): option_list = BaseCommand.option_list + ( make_option('--delete', action='store_true', dest='delete', default=False, help='Delete poll instead of closing it'), ) # ... 

    The syntax of option_list can be viewed in the documentation for optparse .

    • thank. exactly what is needed. - fenk