Selecting a render method from a view using the URL

Suppose I have a "test" view, registered for "*" in configure.zcml. The view has a TestView class.

I have two templates, and I want the view to be able to select the template based on the request URL, like so:

My question is about getting the last part of the URL as a parameter to the call method of the view. How can I do that?


Why not just register two views with the same class but with different templates ?

Or maybe you could define which template to use in the and call it like:

I wrote this blog post addressing exactly what you need first:

After you got the name its easy to conditionally render one or the other template.

1 Like

Doesn't that just build another copy of what's already in request['TraversalRequestNameStack']?

In fact it more or less does. But at every step one may not return self, but a different object - even one out of ZODB. And instead of building a list one may want to build a dict or what you like out of it as well. And it does this at traversal time. So many additional options.

1 Like

Here's another working example, that given a url /@@stream/tag/foo extracts the "foo" tag argument: