在以下 python/html 脚本中,我想在变量“condition”的值等于“1”时自动刷新网页。这样页面就会自动显示包含变量“myText”的新文本。变量“myText”可以包含任何文本,以下脚本只是一个示例。
#!/usr/bin/python
import cherrypy
import os.path
import struct
from auth import AuthController, require, member_of, name_is
import subprocess
import commands
class Server(object):
led_logout=0
led_restart=0
condition=0
_cp_config = {
'tools.sessions.on': True,
'tools.auth.on': True
}
auth = AuthController()
@cherrypy.expose
@require()
def index(self,logout=''):
html = """
<html>
<head>
</head>
<body>
<p>{htmlText}
<p>
<a href="?logout=1" onclick="return confirm('Are you sure you want to logout?');"><img src="images/Logout.png"></a>
</ul>
</body>
</html>
"""
myText = ''
myText = "Hello"
if logout:
self.led_logout = int(logout)
if self.led_logout:
print "Logout !!!!!"
AuthController().logout('/?logout=0')
return html.format(htmlText=myText)
index.exposed = True
#configuration
conf = {
'global' : {
'server.socket_host': '0.0.0.0', #0.0.0.0 or specific IP
'server.socket_port': 8085 #server port
},
'/images': { #images served as static files
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.abspath('/home/ubuntu/webserver/images')
}
}
cherrypy.quickstart(Server(), config=conf)