> 1. I think there is no controller in Pyramid and I think the Views > probably plays the role (for what is there in Pylons). In Pylons, I could > have multiple controllers (or python files/modules in controller folder to > say in crude way). I think in Pyramid, it would probably be the same (new > python modules) but route needs to be defined. The view.py is provided when a > Project is created.
Views can be structured any way you want. You can create classes and make the views methods of the classes (using the @view_config decorator) in their own separate .py files; you can make them plain python functions with the @view_config decorator or declare them with the configurator in the __init__ module; you could clump them all up into one .py file, into separate .py files, etc… It's really up to you and how big your application is. I personally have 90% of the "controllers" separated into their own modules. So for my user's billing page, there is a "view" module named "billing.py" and inside of it is a class "class BillingView" that extends a base view. Inside the class is all of the "view" methods, like update, display, etc... You can name the class whatever you want, it isn't significant - only to you, the programmer. I like the class based way because I can extend it with a base class that can provide a number of useful abstract methods and members. I have a few views that are just straight python functions with a @view_config decorating it. These I will typically clump into a module based on shared functionality. So I have a lot of custom error handling views (like 4 or 5) and they are all in a "errors.py" module. Same with any others that are composed that way. I also use traversal, so I have a separate resources.py module that defines *all* of my traversal object trees. > 2. In Pylons, lib folder contained 3rd party code and any other code > that doesn’t fit in the main application. Is there anything similar in > Pyramid? Or any similar convention? I put 3rd party code inside a directory called "libraries" so: pyramid/myapp/libraries right alongside it is a directory called "views", "templates", "models", &c… Hope that helps!!! I may write a blog post on how I've structured my Pyramid app, as I see this type of question a lot and I'm using Pyramid in a heavy production environment very successfully.
signature.asc
Description: Message signed with OpenPGP using GPGMail
