What are the Pyramid / Python equivalents of Model - View - Controller of PHP Frameworks such as Kohana?
In Pyramid "Model" is .... and it is used for .....
In Pyramid "View" is .... and it is used for .....
In Pyramid "Controller" is .... and it is used for .....
I am trying to understand Pyramid's logic. As an addition to the answer, any help, documentation etc would be appreciated.
Thanks.
Pylons, one of the two frameworks that joined together to be Pyramid ( the other was repoze.bfg ) was "close" to an MVC system.
I put close in quotations, because over the past few years a lot of people have been fighting about what MVC means... and many projects that once touted themselves as "MVC" started to call them "MTC" (model template controller) "MT" (model template) or "MV" (model view). Everyone agrees on what the "model" is, but exactly what the "view" and "controller" map to - on a given framework - can be a point of contention.
Pyramid and pylons both have a "dispatcher" functionality to set up the mapping for a request. Under pylons its in config/routes.py ; under Pyramid it's a little different -- the default scaffolds have the routing in app/init.py , but you're free to break it out into app/routes.py or use config.include() to push it into you 'handlers' or config.scan() to pull it from your 'views'.
'handlers' in pyramid are provided by pyramid_handlers, and are really just 'views' with a bunch of auto-generation stuff in there. If you wanted to, your apps could use both handlers AND views ( mine do ).
In any event, depending on how you interpret MVC / MTC / etc , this is a loose table of what you might want:
|| mvt | mvc | mvc
==========================================================================
model || sqlalchemy | sqlalchemy | sqlalchemy
view || views/handlers | templates | views/handlers + templates
controller || | views/handlers | dispatch/routing
template || templates | |
Quick note- I'm defining the above not based on my interpretation or what the 'official' MVC definition is... It's based in relation to how other popular frameworks market themselves.
If you want, with pyramid you can simulate the MVC pattern:
Class HomeController(object): def __init__(self, request): self.request = request def form_proc(self): name = self.request.params['name'] ... bla, bla, bla ...
In the config you can add something like:
config.add_handler('home', '/home/{action}', handler='mypackage.HomeController')
If you put this url in your form action -> http://SERVER_NAME/home/form_proc, you can process the form.
Pyramid give you all the flexibility if you need it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With