title: How to execute file.py on HTML button press using Django?
body: <p>My goal is to click an HTML button on my Django web page and this will execute a local python script.</p>
  
  <p>I am creating a local web application as an interface to a project.  This will not be hosted and will always just run on my local machine.  My project is run with a python script (which carries out numerous tests specific to my project).  All I need is for a button in my web interface to execute this script on my machine.</p>
  
  <p>I have a template index.html where the whole web page is located.  I presume I need to call some form of views function possibly when the button is pressed?</p>
  
  <p><a href="https://stackoverflow.com/questions/26299492/how-to-execute-python-code-by-django-html-button">How to execute python code by django html button?</a></p>
  
  <p>This question suggests:</p>
  
  <pre><code>def index(request):
      if request.method == 'GET':
          return render(request, 'yourapp/index.html', {'output': ''})
      elif request.method == 'POST':
          py_obj = mycode.test_code(10)
          return render(request, 'yourapp/output.html', {'output': py_obj.a})
  </code></pre>
  
  <p>I tried this just as a test but nothing happened when I went to the URL (located in the appropriate views.py):</p>
  
  <pre><code>def runtest(request):
      print("Hello World")
      Popen(['gnome-terminal', '-e', 'echo "Hello World"'], stdout=PIPE)
      return
  </code></pre>
  
  <p>However I don't quite understand if this achieves what I need it to, I am struggling to understand what the answer is suggesting.</p>
  
  <p>Where in the Django framework can I specify a call to a local python script when a button is pressed?</p>
  
  <p>(I have very limited experience with web applications, this is simply just meant to be a simple interface with some buttons to run tests)</p>