I had an idea about this. When you want to associate data with a
callable you can use a partial function. For instance:
# views.py
def my_view(title, request):
....
# __init__.py
import functools
title = "My Title"
view1 = functools.partial(my_view, title)
config.add_view(view1, ...)
Or you could write a wrapper for view_config that does this.
I've never needed additional view data like this because my titles are
in my templates or in my view code. (I have a Mako site template with
a 'page_title' function which I override in the individual templates.)
But if you can't specify the title in either of those places or in the
context, then I'd use a partial function like this.
Outside Pyramid I'd use a callable class:
class MyClass:
def __init__(self, title):
self.title = title
def __call__(self, request):
# Use self.title.
But that wouldn't work as a view class because Pyramid makes certain
assumptions about view classes that are incompatible with this. You
might be able to configure an instance of it:
config.add_view(MyClass("My Title"), ...)
But I haven't tried it and I don't know whether Pyramid would treat it
like a function.