Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want a button on my website that will execute a python script

I am currently making a website using django. Now I want to execute a python script from my template/view with a button on the website. It should be possible but to be honest I don't know how.

An example would be best.

Thanks for any help at all.

like image 550
wagner-felix Avatar asked Sep 29 '11 08:09

wagner-felix


People also ask

Can you run a Python script on a website?

It is possible to run Python in a web page (on the client side) using frameworks such as Pyjamas and Skulpt. If CGI / server sided python execution is not what you ale looking for, see : skulpt.org - this appears to execute python in the browser.

What button do you press to run a Python program?

To start a Python interactive session, just open a command-line or terminal and then type in python , or python3 depending on your Python installation, and then hit Enter . Here's an example of how to do this on Linux: $ python3 Python 3.6.


1 Answers

Well got it working now and just thought I would write my answer:

view.py:

import script as gh

def get_hostname(request):
        gh.main()
        return HttpResponseRedirect('/')

urls.py:

... 
url(r'^get_hostname/$', 'thinco.views.get_hostname'), 
...

somewhere in template:

...
     <form action="/get_hostname/" method="GET">
        <input type="submit" value="Liste der Thin Clients laden"> 
    </form>
...
like image 165
wagner-felix Avatar answered Sep 19 '22 13:09

wagner-felix