0

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?

2
  • You can use JS or direct call to your python script. Commented Dec 28, 2017 at 11:01
  • or you can just execute a CMD on click Commented Dec 28, 2017 at 11:11

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.