You typically return an Article object from the URL crawl identification part.
What happens with the crawl is that for each element of the URL path, an object is scanned and a new current object is created to search for the next path element.
So, for Article root object needs something matching this name, and the result of this search is a new “current” object, and then 5048230b2485d614ecec341d looked at on this new object.
So, what you are looking for is a dispatcher object that searches for articles based on the longer identifier you passed in and returns your instances of Article :
class Root(object): __name__ = None __parent__ = None def __init__(self, request): self.request = request def __getitem__(self, key): if key == 'articles': dispatch = ArticleDispatcher(self.request) dispatch.__name__ = key dispatch.__parent__ = self return dispatch raise KeyError(key) class ArticleDispatcher(object): __name__ = None __parent__ = None def __init__(self, request): self.request = request def __getitem__(self, key):
Notice how I returned ArticleDispatcher when you use the URL /articles path, as well as how I set the __name__ and __parent__ ; you will need those that can create URLs for these instances.
The returned Article object now contains the actual article data, and the view can access this information when rendering.
You really want to go and study the Pyramid Traversal tutorial, which explains this in more detail.
source share