4 ms·
Of these frameworks, Pyramid is the only one I know of that uses the concept of traversal. Traversal is an elegant way to tame big projects. Whenever I look at
by hathawsh 7y ago
Of these frameworks, Pyramid is the only one I know of that uses the concept of traversal. Traversal is an elegant way to tame big projects. Whenever I look at a web framework, I look for traversal and I'm always a little disappointed to see it's missing.
Traversal means the framework treats each path segment in the URL as a possible branch in a tree of resources provided by the app. After completing traversal, the framework looks up a context-dependent view and checks a contextual access control list before calling the view. It feels right to declare security restrictions and other conditions outside the view.
- j88439h84 7y agoPyramid is so well designed. The maintainers have a philosophy of "if it's not documented, it's broken", and it shows. They even have an amazing defense-of-design document. http://docs.pylonsproject.org/projects/pyramid/en/latest/designdefense.html http://docs.pylonsproject.org/projects/pyramid/en/latest/des...
- rahimnathwani 7y agoWhy is this better than using mixins when defining a Django CBV?
- coleifer 7y agoClass based views: I've got 99 methods and I can't remember the right one.
- ianamartin 7y agoPyramid is the best of all of these if you don't need async. Look at, for example, the best of all the flask tutorials of all time, Miguel Greenberg. He still has to create a ton of the boilerplate and then restructure the app half way through. Pyramid is the goldilocks of frameworks: Just enough to get you going without insanity, and not too much to bog you down. Here's the real truth: If you're going to build anything nontrivial, you need a ton of stuff that Flask doesn't give you, and the packages that are easy to install and add to your project are mostly anti-pattern. If you are going to build something nontrivial with Django, you're going to have to tear out large parts of it and redo stuff. Pyramid is the best balance. The WebSauna team si doing some amazing stuff, and I'm working on something similar that's a little more lightweight. Pyramid is a very active ecosystem. Just a little less exciting because we have some conceptual relationships with Pylons. If you need async or websockets, I use starlette/fast-api for endpoints that get hit from my mako templates.
- vonseel 7y agoMaybe 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?
- hathawsh 7y agoThat'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.