【发布时间】:2015-12-01 05:09:24
【问题描述】:
我正在尝试找出一种方法,我需要让两个不同的页面调用一个函数,并且该函数将根据调用的函数相应地处理请求。
流程可以是基于调用函数的predict function 句柄,也可以是向调用函数返回一个值,然后调用函数页面重新加载以显示必须显示的结果。
Class GSpam:
@cherrypy.expose
def main(self,contents=""):
return call predict
@cherrypy.expose
def alt(self):
return """<html>
<div align=center>
<body>
<br>
<br>
<form method="post" action="predict">
<input type="text" value="Enter post to check" name="text" />
<button type="submit">Predict!</button>
</form>
</div>
</body>
</html>"""
@cherrpy.expose
def predict(self,text):
do some stuff
check which function called and return accordingly
return result
if __name__ == '__main__':
port = 80
api = cherrypy.dispatch.RoutesDispatcher()
api.connect('home','/',controller=GSpam,action='main')
conf = {'/': {'request.dispatch': api}}
cherrypy.config.update({
'server.socket_host' : "0.0.0.0",
'server.socket_port' : int(port),
'server.thread_pool' : 10,
'engine.autoreload.on' : False,
'response.timeout' : 10
})
app=cherrypy.tree.mount(root=None,config=conf)
我以前没用过cherrypy。任何帮助表示赞赏。
【问题讨论】: