I’d look into defining the views the same place you define the routes, since you’ll need to generate routes with this same “foo” pattern. Something like:
def includeme(config):
for suffix, url, renderer in generate_foo_urls(“/a/“):
route_name = f”a:{suffix}”
config.add_route(route_name, url)
config.add_view(“foo.bar.view”, route_name=route_name, renderer=renderer)
Or flip that on its head:
def generate_foo_views(config, view, url_prefix):
for suffix in [“a”, “a.json”, “b”, “b.json”]:
route_name = f”a:{suffix}”
config.add_route(route_name, url_prefix + suffix)
config.add_view(view, route_name=route_name, renderer=‘json’ if suffix.endswith(‘json’) else ‘1’)
Depending on the details of `route_pattern=“foo”` these samples might not be exactly applicable, but I think some variation of them will work for you.