首先,不确定javascript部分是否有意义,就将其省略。另外,打开 p
标签但不关闭它。不知道您的模板引擎是什么,但是您可以只使用纯python传入变量。另外,请确保在链接周围加上引号。因此,您的代码应类似于:
class Server(object): _cp_config = { 'tools.sessions.on': True, 'tools.auth.on': True } auth = AuthController() @cherrypy.expose @require() def index(self): f = open ("file.txt","r") link = f.read() f.close() myText = "Hello World" html = """ <html> <body> <p>%s</p> <a href="%s" ><img src="images/go_online.png"></a> </body> </html> """ %(myText, link) return html index.exposed = True(顺便说一句,%s是字符串占位符,它将在多行字符串的末尾填充%(firstString,secondString)中的变量。



