【发布时间】:2014-01-29 11:19:37
【问题描述】:
Flask 有一个 url_for 方法调用,用于从其全局设置文件夹中设置 url。
我如何管理与 CherryPy 类似的事情?
【问题讨论】:
Flask 有一个 url_for 方法调用,用于从其全局设置文件夹中设置 url。
我如何管理与 CherryPy 类似的事情?
【问题讨论】:
如果你使用routes dispatcher,你有它的url_for。
【讨论】:
这是你要找的吗?
您可以通过
访问挂载的 url 处理程序cherrypy.tree.apps[mount_point].root
root 始终是挂载点的挂载实例。所以反向函数看起来像:
def reverse(cls):
# get link to a class type
for app_url in cherrypy.tree.apps.keys():
if isinstance(cherrypy.tree.apps[app_url].root, cls):
# NOTE: it will return with the first mount point of this class
return app_url
how to get url of an object in cherrypy?
希望这会有所帮助!
【讨论】: