Reputation: 105
I am using Django as the framework but I'm pretty new to Django.
I have an HTML file with me that is showing up using Django as the framework. I have added a Submit button to the HTML page. I have a python script saved locally on my server. Is there any way to run the python when clicking on the Submit button? Or can this be done when clicking on an image/logo?
Upvotes: 0
Views: 2976
Reputation: 6830
invoking a python script on click of HTML button can be accomplished using python-django framework.
The ajax for it is written this way
<input type = “button” id=”b1″ value=”1″>
<script>
$(document).ready(function(){
$("#b1").click(function(){
$.ajax({
method: "GET",
url: "type your python script path here",
data: {"place" : value},
dataType: "text",
success: function(result){
var data=JSON.parse(result);
console.log(result);
}
});
});
</script>
hope this works
Invoking a python script can be accomplished using python-django framework.
1.Install django- pip install django
2.create a django project and an app.
3.add urls accordingly.
4.write your python script in views.py
5.invoke the function in views.py from your html file using ajax.
Refer django documentation for complete details.
Upvotes: 1