On Thursday, 21 January 2021 12:52:44 GMT Hamish McIntyre-Bhatty
wrote:
I haven't looked at Flask in detail, but one way to do it would be to
use a GET or POST value when the button is submitted in the form, so
it
eg redirects to /control.html?action=play.
Thanks Hamish. I did wonder if that might be the only way, but it
seemed a
bit clunky and felt that there ought to be something more
sophisticated that
I've missed.
One trouble that I've found with Flask is that on its own its fairly
straightforward, but much of what is done is done my the loading of
flask
modules and other helper libraries. It isn't always obvious which of
those
module or libraries to study to find what I need.
That's why I've been trying to find an example from someone who has
done
something similar. I've found a number of examples using javascript
(I even
used one myself for the original WMT Webserver), but they all simply
redirect
to another page. I need to execute a line of Python.
You might need the subprocess.open method or .run
- https://docs.python.org/3/library/subprocess.html
This lets you run out of process functions (ie shell scripts, python
scripts etc) without leaving the wsgi world.
The other thing I was thinking was that your original code mentions
‘socket’, so you might be wanting to make some sort of websocket
connection from the browser. I’d try and avoid that if possible as it
really is a bit of a nightmare depending how Flask is being hosted, and
what you use to set up the web sockets. Stick to the GET or POST as
Hamish says, with a redirect on successful submission (to avoid web
browser history allowing the user to get in a muddle)
--
Next meeting: Online, Jitsi, Tuesday, 2021-02-02 20:00
Check to whom you are replying
Meetings, mailing list, IRC, ... http://dorset.lug.org.uk
New thread, don't hijack: mailto:dorset@mailman.lug.org.uk