我试图找出一种方法,我需要有两个不同的页面调用一个函数,函数将根据调用的函数相应地处理请求。在
流可以是基于调用函数的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)
我以前没用过樱桃糖。感谢任何帮助。在
创建一个私有方法如何:
下面是我如何尝试一些对我有用的方法。我在函数本身上使用了形式action。这并不能完全根据问题中提到的哪个函数调用另一个函数来处理,但是调用另一个函数的同一个函数通过对自身使用form action来处理自己。在
相关问题 更多 >
编程相关推荐