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.
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.
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.
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>
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With