简体   繁体   中英

How can I access elements in the HTML file via Python?

I have an HTML file where my website is built. Next door, I have a Python file where I will write methods. I want when the save button is clicked, it executes a method in the Pythonfile and then writes the values to text area.

When the Start button is pressed, values read by a sensor are to be written into the two text fields (above) and disable this butten, bat enable the other button.

MyHTML-Code.

<div class="container">
  <h1 id="h1Title" font="43px">Temperature und humidity</h1>
  <p id="pTemperature " font="25px">Temperature </p>
  <p id="pHumidity" font="25px">humidity</p>
  <p id="OutputTemp" font="25px">--°C</p>
  <p id="OutputHumi" font="25px">--%</p>
  <span class="cbtn" id="e6" font="25px"><button id="buttonStart">Start</button></span>
  <span class="cbtn" id="e7" font="25px"><button id="buttonStop">Stop</button></span>
  <p id="pExplemation1" font="25px">Green temperatures Range: between</p>
  <textarea id="TempGreenMin" font="25px"></textarea>
  <p id="pAnd1" font="25px">and</p>
  <textarea id="TempGreenMax" font="25px"></textarea>
  <p id="pExplemation2" font="25px">Gree humidity range: between</p>
  <textarea id="LumiGreenMin" font="25px"></textarea>
  <p id="pAnd2" font="25px">and</p>
  <textarea id="HumiGreenMax" font="25px"></textarea>
  <span class="cbtn" id="e8" font="25px"><button id="buttonSave">Save</button></span>
</div>

You want to have a look at Flask . It is a framework that will allow you to build a website run on python, and run it on your computer so that you can present your readings as an html.

You could also simply have your code to printout the sensor readings to a console.

You have to send a POST request to your API (server) in order to indicate whatever reads the weather to do it's task. Said POST request would then return the information which you can display on the page.

Creating Web APIs with Python and Flask

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM