Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Maybe a semi-realistic example would help us understand what you mean by the path segment branch in tree of resources part? Is that like /api/<resource type>/<resource make>/<resource model>/ would boil down to /api/cars/ford/fusion/ with cars, ford, and fusion each being a branch in the tree?


That's right, except that 'api' is probably a resource also. Your app provides a root resource with a __getitem__ method. Pyramid tries `context = root['api']`, then `context = context['cars']`, then `context = context['ford']`, and so on, until it uses up all the path segments or a __getitem__ raises KeyError. Then it looks up the view for the final context and calls it if all the conditions are met for the view configuration.

That's traversal in a nutshell. Resources can be database objects or any object with a __getitem__ method. Everything about traversal is customizable, but it's rare to need much customization.

Also, if your resources have __parent__ and __name__ attributes, you can ask Pyramid to generate the URL of any resource and view using `request.resource_url(resource, view_name)`, which is really handy for ensuring URLs don't break.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: