I have this Command(BaseCommand) class with this defined:
make_option('--username', action='store_true', dest='username', default=None),
Then I try to run it like this:
python manage.py thescript --username=something
The output is:
manage.py: error: --username option does not take a value
Why?
EDIT
I am always getting None:
class Command(BaseCommand):
args = '--username=username ...'
help = '...'
option_list = BaseCommand.option_list + (
make_option('--username', action='store', default=None, help='...'),
)
def handle(self, *args, **options):
print options['username']
The line store_true will cause the command to store the boolean value True if the argument --username is given, rather then storing the next value.
I suspect that doing something along the lines of action='store' would do what you expect.
I think you're currently using optparse, correct? If so, you can find a full listing of the different kinds of actions available in the optparse documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With