[Solved]-Passing arguments to management.call_command on a django view


In your command you should find the option definitions which should look like the following:

make_option('-tzsub', dest='tzsub', action='store_true', help='Help description...')
make_option('-e', dest='e', action='store_true', help='Help description...')

Have a look on them and take into account “dest” argument for each one. Assuming you defined dest=’tzsub’ for -tzsub and dest=’e’ for -e (like in the example above), you should call the command in this way:

management.call_command('artifact_db_loader','artefacts', tzsub=True, e=True)

This is the same of calling the command from your console like this:

python manage.py artifact_db_loader artefacts -tzsub -e

Of course if the parameters need any arguments (so you have action=’store’ in the option definition) simply replace the boolean argument with the value you need. For instance:

management.call_command('artifact_db_loader','artefacts', tzsub='wow!', e=7)

This is the same of calling the command in this way:

python manage.py artifact_db_loader artefacts -tzsub "wow!" -e 7

Leave a comment