Django admin user commands - passing a list of strings to args

I have a list of lines that I would like to pass to args in my django user command.

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

How to do it from python function:

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

I'm tired of passing my argument list:

[1]:

    management.call_command('commandname', list)

and

[2] as a loop:

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

but both refused after entering the user command

+3
source share
1 answer

The call_command method uses the Arbitration Argument List for the arguments of the command.

So you need to use:

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

The same as:

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

Additional Information:

+7
source

All Articles