2

I'm creating an Akhet (Pyramid) web application. How can one generate in a mako template the URL for a given Handler/view ?

I'm looking for the equivalent of Pylons' ${url(controller="users", view="list")

tshepang
  • 12,111
  • 21
  • 91
  • 136
ascobol
  • 7,554
  • 7
  • 49
  • 70

2 Answers2

7

You need to use route_url. It's available in the templates in request.route_url.

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

for example

Rick
  • 15,484
  • 5
  • 25
  • 29
  • it indeed works. It took me some time to understand your answer, which is not complete. In the case of akhet, assuming config.add_handler('users', '/users/{action}', ...) in the setup as Michael said, you can call: request.route_url('users', action='someaction'). To obtain a relative path (without http://), the method to call is route_path instead of route_url. – ascobol Jul 04 '11 at 20:42
2

Akhet exposes the URLGenerator object as a renderer global, so you can just use url('users', action='list'), assuming config.add_handler('users', '/users/{action}', ...) in your setup.

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

Michael Merickel
  • 23,153
  • 3
  • 54
  • 70
  • I don't see where it's written in the page you linked but url(handler, action="someaction") works. Thanks! – ascobol Jun 09 '11 at 07:42