Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
Multiple arguments with values to custom management command

How do I pass multiple arguments with values, from command line, to a custom django management command?

def add_arguments(self, parser):
    parser.add_argument('str_arg1', nargs='+')
    parser.add_argument('int_arg2', nargs='+', type=int)

When I run:

./manage.py my_command str_arg1 value int_arg2 1 --settings=config.settings.local

I get the following values in options:

options['str_arg1'] = ['str_arg1', 'value', 'int_arg2']
options['int_arg2'] = [1]

Tried searching in documentation and online for a solution and multiple ways of passing the arguments with no luck. Django version is 1.10.

Thanks

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The way you have defined the arguments means they are positional arguments. There's no sensible way to have multiple positional arguments which consume an unknown amount of values.

Modify your parser to specify them as options instead:

parser.add_argument('--str-arg1', nargs='+')
parser.add_argument('--int-arg2', nargs='+', type=int)

And modify the call:

./manage.py my_command --str-arg1 value --int-arg2 1
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!