I have very simple web page example read from html file using python. the html called led.html as in bellow:
<html>
<body>
<br>
<p>
<p>
<a href="?switch=1"><img src="images/on.png"></a>
</body>
</html>
and the python code is:
import cherrypy
import os.path
import struct
class Server(object):
led_switch=1
def index(self, switch=''):
html = open('led.html','r').read()
if switch:
self.led_switch = int(switch)
print "Hellow world"
return html
index.exposed = True
conf = {
'global' : {
'server.socket_host': '0.0.0.0', #0.0.0.0 or specific IP
'server.socket_port': 8080 #server port
},
'/images': { #images served as static files
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.abspath('images')
},
'/favicon.ico': { #favorite icon
'tools.staticfile.on': True,
'tools.staticfile.filename': os.path.abspath("images/bulb.ico")
}
}
cherrypy.quickstart(Server(), config=conf)
The web page contain only one button called “on”, when I click it I can see the text “Hello World ” display on the terminal.
My question is how to make this text display on the web page over the “on” button after click on that button?
Thanks in advance.
You’re going to want to use some kind of templating system. I use Jinja2 it’s great!
Instead of…
you would use…
Hope this helps!
Andrew