Python 使用CherryPy进行路由调度
我正在尝试将CherryPy应用程序从标准CherryPy调度切换到RoutesDispatcher 下面的python代码使用标准CherryPy分派正确地路由Python 使用CherryPy进行路由调度,python,routes,cherrypy,Python,Routes,Cherrypy,我正在尝试将CherryPy应用程序从标准CherryPy调度切换到RoutesDispatcher 下面的python代码使用标准CherryPy分派正确地路由/。我的目标是将相同的代码转换为使用RoutesDispatcher运行。我已经找到了一些代码片段,但还没有找到使用路由的CherryPy应用程序的完整示例 class ABRoot: def index(self): funds = database.FundList() template
/
。我的目标是将相同的代码转换为使用RoutesDispatcher运行。我已经找到了一些代码片段,但还没有找到使用路由的CherryPy应用程序的完整示例
class ABRoot:
def index(self):
funds = database.FundList()
template = lookup.get_template("index.html")
return template.render(fund_list=funds)
index.exposed = True
if __name__ == '__main__':
cherrypy.quickstart(ABRoot(), '/', 'ab.config')
我一直在尝试将我发现的各种部分教程中的代码进行组合,但没有任何运气
我必须对
\uuu main\uuu
进行哪些更改,才能通过RoutesDispatcher
加载和路由?以下是我最终使用的代码。我需要做出的改变对我来说并不明显:
dispatcher.explicit=False
class ABRoot:
def index(self):
funds = database.FundList()
template = lookup.get_template("index.html")
return template.render(fund_list=funds)
if __name__ == '__main__':
dispatcher = cherrypy.dispatch.RoutesDispatcher()
dispatcher.explicit = False
dispatcher.connect('test', '/', ABRoot().index)
conf = {
'/' : {
'request.dispatch' : dispatcher,
'tools.staticdir.root' : "C:/Path/To/Application",
'log.screen' : True
},
'/css' : {
'tools.staticdir.debug' : True,
'tools.staticdir.on' : True,
'tools.staticdir.dir' : "css"
},
'/js' : {
'tools.staticdir.debug' : True,
'tools.staticdir.on' : True,
'tools.staticdir.dir' : "js"
}
}
#conf = {'/' : {'request.dispatch' : dispatcher}}
cherrypy.tree.mount(None, "/", config=conf)
cherrypy.quickstart(None, config=conf)
“dispatcher.explicit=False”行的用途是什么?在试图解决升级到CherryPy 3.2的问题时,我看到了对这一点的引用,但是它被应用到了映射器“dispatcher.mapper.explicit=False”。上面的代码在有行和没有行的情况下似乎都是一样的。