如何使用Pyramid和Akhet生成URL?

2 投票
2 回答
974 浏览
提问于 2025-04-16 19:12

我正在创建一个Akhet(Pyramid)网络应用。 请问在mako模板中,如何生成一个特定处理器/视图的URL呢?

我想找到类似于Pylons中的${url(controller="users", view="list")的用法。

2 个回答

7

你需要使用 route_url。它可以在模板中通过 request.route_url 来使用。

<a href="${request.route_url('import')}">Import</a>

比如说

2

Akhet把URLGenerator对象作为一个全局的渲染器,这样你就可以直接使用url('users', action='list'),前提是你在设置中有config.add_handler('users', '/users/{action}', ...)

http://docs.pylonsproject.org/projects/akhet/dev/api.html#module-akhet.urlgenerator

撰写回答