3

I have a list of strings which I would like to pass into args in my django custom command.

list = ['abc', 'def', 'ghi', etc...]

How can I do this from within a python function:

management.call_command('commandname', args, options) 

I've tired passing on my list of args both:

[1] directly:

    management.call_command('commandname', list)

and

[2] as a loop:

    management.call_command('commandname', (abc for abc in list))

but both have failed after entering the custom command

snakesNbronies
  • 3,329
  • 9
  • 41
  • 72

1 Answers1

10

The call_command method is using Arbitrary Arguments List for command arguments.

So, you need to use:

list = ['abc', 'def', 'ghi']
management.call_command('commandname', *list)

Which is the same than:

management.call_command('commandname', 'abc', 'def', 'ghi')

Related information:

Community
  • 1
  • 1
math
  • 2,775
  • 3
  • 22
  • 28