khun wrote: ↑
Sun Dec 03, 2023 1:10 am
And to clarify: I am trying to make a web page that lets users change On/Off settings for ovens in the house. So I made a python script that creates a web page, so far so good. But when a user clicks a radio button there, I don't know how to "transmit" that action to the python code.
I don't want to have a "submit" button, but the change to happen at the moment the radio button is changed.
I have managed to get the python code to be rerun when a radio button is changed (by the onclick), but don't see how I can tell the python code what was changed.
The easiest way to explain that is like this .
You go to a url. The web server on the other side gives you a string of bytes, which the browser uses to display something on the screen.
There. It's 100% done. It is static.
All the communication that will ever happen between browser and server happens there. The browser asks for the contents of an address and the server gives the content back.
Clicking something in the browser and making something else happen in the server in response to that click, involves the browser reaching out to the server again, could be the same address or not, but this time with a bit more data to tell it, "button x was clicked". The server then goes, "oh, in that case, then I give you this other thing"
That is what submit does.
But it is still very static.
Now, the code in that page executes when the page is displayed. And if you coded it to do x it will do that x when you click the right button.
But what that java script code is doing is more if the same. Instead of submitting data to the server with a submit button which would result in the browser receiving a new set of HTML to refresh the screen with, the java script executed calls the server on its own, without doing anything to the page. And it will also wait for the server to give data back to it. And when it gets that data, it will update something on the page, without the page ever submitting anything.
Now I work with flask a lot, so I know how to further explain that to you, which also uses python, but it is not what you are doing, so there is no point for me to go any further because it will not apply to you. But even flask still runs on a web server piece of software that does what? It gets a request at an address with some optional data, gives it to the processor to figure out how to answer and what to answer, then take the results of that crunching and send back down the the clients browser to to the displaying.