【问题标题】:Is there an alternative to url_for for CherryPy?CherryPy 的 url_for 是否有替代方案?
【发布时间】:2014-01-29 11:19:37
【问题描述】:

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

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

【问题讨论】:

    标签: python flask cherrypy


    【解决方案1】:

    如果你使用routes dispatcher,你有它的url_for。

    【讨论】:

      【解决方案2】:

      这是你要找的吗?

      您可以通过

      访问挂载的 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?

      希望这会有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-10-07
        • 2012-09-02
        • 2016-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-13
        相关资源
        最近更新 更多