我使用python从html文件中读取了非常简单的网页示例。在HTML叫led.html在波纹管:如何使用python和HTML在网页上显示文本
<html>
<body>
<br>
<p>
<p>
<a href="?switch=1"><img src="images/on.png"></a>
</body>
</html>
和Python代码是:
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)
该网页只包含名为“上的”一键,当我点击它,我可以看到在终端上显示文本“Hello World”。 我的问题是如何使该文本显示在网页上的“开启”按钮后点击该按钮? 在此先感谢。
安德鲁嗨, 谢谢你这么多的解决方案,只是其需要将“导入”改为“来自”,因为我的原始HTML也不大,所以它很好地将它们合并到一个文件中。 我试图修改代码,让它显示“Please wait ....”约5秒钟,然后显示“Ok!its done”,但是我不能。 如果开关: self.led_switch = INT(开关) =会将myText “请稍候......” 做某些任务的花费大约5秒钟会将myText = “OK!它做” – Linux
好吧,我更新显示“Please Wait”的代码在5秒后显示为“Ok!it's done”。那是你要做的吗? –
@majidhantoosh你可以更新你的问题,以反映更新代码? – btel