How Can I Trigger A Python Script In Background From Html Tag Button, In Django?
Please, how can i run a python script from my Django platform? I have a custom html page and i have a button tag () from which i would like to trigger
Solution 1:
Just add the script to a view and call it like this. i.e in the views.py
file
<a href = {% url 'wonderful_script' %} class="btn btn-primary" role="button"> Wonderful Parser </a>
Make sure you bind that view to an url in urls.py too.
url(r'^parse/$', wonderful_script, name='wonderful_script')
Here the wonderful_script
in the middle is the view that you defined in the views.py. It must have all the code of your parser script.
Solution 2:
If you already have a view for page that you want to add a button to it you can do something like this
{# test.html #}
<form action="" method="post">
{% csrf_token %}
<input type="submit" name="button_name" value="run_script">
</form>
and your view:
deftest_view(requests):
if(request.method == 'POST' && request.POST['button_name'] == 'run_script'):
# do what you want when button clickedelse:
# other things in your views if you havereturn render(requests, 'test.html', {})
Post a Comment for "How Can I Trigger A Python Script In Background From Html Tag Button, In Django?"