I have a route configured like this in my app:
config.add_route('book', 'book/{id}).
When I make a GET request, e.g localhost:8000/book/2
, I would like to output route pattern like the one defined in config, so the output would be 'book/{id}'
.
I have tried regex, but maybe there are better ways.
What would be the best way to achieve that?
Use request.matched_route.pattern
. I found it by using the pyramid_debugtoolbar
, searching for "route", and found it under the Request Vars tab with its attributes listed.