I have a command i run from the command line that takes two arguments,-tzusb and -e. I have converted this so that it is called on a django view. I have a little glitch though, How do i pass this arguments to the management.call_command function I have in my views? here is my view for that
def tzusbcsv(request):
management.call_command('artifact_db_loader','artefacts')
return render_to_response('html/upload.html')
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With