python - CherryPy 是否有 url_for 的替代方案?

标签 python flask cherrypy

Flask 有一个 url_for 方法调用,用于从其全局设置文件夹中设置 url。

我如何管理与 CherryPy 类似的事情?

最佳答案

这是您要找的吗?

您可以通过以下方式访问已安装的 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?

希望这有帮助!

关于python - CherryPy 是否有 url_for 的替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21045092/

相关文章:

python - python中的唯一 session ID

python - iPython:类似操作的命令

python - 在 Flask 应用程序中使用 Alembic 和 Flask-SQLAlchemy 检测对 models.py 的更改

javascript - AJAX 请求无法读取更新的 session /全局变量

python - Flask api 中的自定义静态路径?

CherryPy 服务器错误日志

python - 导入错误 : cannot import name wsgiserver

java - 未找到 JPype 类

python - 如何将 pandas 数据框舍入为分数?

python - Apache mod_rewrite 与多个 Web 应用程序