6

Is there a way to pass command line arguments to a script using django runscript ? The script I am trying to run uses argparse to accept command line arguments.

Command line execution of the script:

./consumer --arg1 arg1 --arg2 arg2

Both arg1 and arg2 are required options.

We tried using script-args but unable to figure out how to use it in this context.

1
  • runscript can't run any Python script but requires a special script that implements a run(*args) method. You can't pass arguments to the script that way. Commented Jul 12, 2016 at 14:03

2 Answers 2

4

Update in 2020: use --script-args

https://django-extensions.readthedocs.io/en/latest/runscript.html#passing-arguments

Sign up to request clarification or add additional context in comments.

1 Comment

Django-extensions is a good package, but its documentation is poor.
2

Take a look at Django's Commands

class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument('--arg1', help="Something helpful")

    def handle(self, *args, **options):
        print options['arg1']

And when run:

$python manage.py your_command --arg1 arg
arg

Command works nicely for this sort of thing, as Selcuk said, you can't use arguments in this fashion using RunScript extension.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.