4 ms·
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']`,
by hathawsh 7y ago
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.