On 21/01/2021 13:03, Terry Coles wrote: > 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.
The only other way I particularly know is to use client-side Javascript to make that request without reloading the page. I know it is also possible to respond to the result from the server, for example with a callback, but I can't provide a good example of how to do this because I lack the expertise. If I spend some time later I my be able to find you an example of it. The only way (that I know of) to do this is to send a request to the server in some way to trigger it to execute the Python line, eg by redirecting to a page or sending a request through some other means. I'm quite happy to be proven wrong though, I'm sure there must be a proper web developer on here who we can both learn from. Hamish
signature.asc
Description: OpenPGP digital signature
-- 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