Is there a way in Pyramid to specify a route in a template, for example, Django templates?

For example, in Django, if I have a url named "home", then I can place the {% url home%} in the template and go to that URL. I could not find anything specific in the Pyramid docs, so I'm looking for a Tou Stack Overflow.

thank

+3
source share
1 answer

The brackets depend on the template engine you use, but request.route_url('home')this is the Python code that you need inside.

For example, in the file of the desired template:

  • jinja2 β†’ {{ request.route_url('home') }}
  • mako / chameleon β†’ ${ request.route_url('home') }

If your route definition includes pattern matching, for example config.add_route('sometestpage', '/test/{pagename}'), you should dorequest.route_url('sometestpage', pagename='myfavoritepage')

+10
source

All Articles