Pyramid:Pyramid / Python 中的 PHP 框架中的 MVC 等效吗?
PHP 框架(例如 Kohana)的模型 - 视图 - 控制器的金字塔/Python 等价物是什么?
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 .....
我试图理解金字塔的逻辑。作为答案的补充,任何帮助、文档等将不胜感激。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Pylons 是连接在一起形成 Pyramid 的两个框架之一(另一个是 repoze.bfg ),它“接近”MVC 系统。
我在引号中加上了引号,因为在过去的几年里,很多人一直在争论 MVC 的含义……并且许多曾经标榜自己为“MVC”的项目开始称其为“MTC”(模型模板控制器)” MT”(模型模板)或“MV”(模型视图)。每个人都同意“模型”是什么,但在给定框架上“视图”和“控制器”到底映射到什么可能是一个争论点。
Pyramid 和 pylon 都具有“调度程序”功能来设置请求的映射。在 pylons 下的 config/routes.py ;在 Pyramid 下有点不同——默认脚手架的路由位于 app/init.py 中,但您可以随意将其分解为 app/routes.py 或使用 config.include()将其推入您的“处理程序”或 config.scan() 以将其从您的“视图”中拉出。
金字塔中的“处理程序”由金字塔处理程序提供,实际上只是带有一堆自动生成内容的“视图”。如果您愿意,您的应用程序可以同时使用处理程序和视图(我的)。
无论如何,根据您如何解释 MVC / MTC / 等,这是您可能想要的松散表:
快速说明 - 我定义上述内容不是基于我的解释或“官方”MVC 定义是什么。 ..它是基于其他流行框架如何推销自己的。
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:
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.
如果需要,您可以使用金字塔模拟 MVC 模式:
在配置中您可以添加类似以下内容:
如果您将此网址放入表单操作中 ->; http://SERVER_NAME/home/form_proc,您可以处理表单。
如果您需要,金字塔将为您提供所有灵活性。
If you want, with pyramid you can simulate the MVC pattern:
In the config you can add something like:
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.
来自金字塔简介:
From the Pyramid Introduction:
我有使用 CakePHP 的经验,现在我开始使用 Pyramid 和 Python。
没有直接映射,但这并不是因为金字塔以奇怪的方式做事,而是因为框架作者滥用了 MVC 术语。
例如,在 Cake 中,有一些类喜欢称为“模型”,但大多数时候只是 ORM 类。控制器主要用作称为“操作”的相关方法的命名空间,这些方法将数据传递到视图,而视图只是模板。
用金字塔术语来说,“资源”就是“模型”,你可以随意使用这里的任何地方,如果你想要 ORM,你可以使用 SQLAlchemy 或 mongodb 或任何地方。
框架本身充当“控制器”,操作称为“视图”,这可以是普通函数或类,您可以随意组织它们。该视图可以使用模板和呈现器来构造发送到浏览器的响应。
希望它有帮助(请原谅我的英语不好)
I have experience with CakePHP and now I'm starting with Pyramid and Python.
There is not a direct mapping but it is not because pyramid does things in weird manner but because framework authors abused the MVC term.
In Cake, for example, there are some classes that they like to call 'Models' but most of the time are just ORM classes. The controllers are mostly used as namespaces for related methods called 'actions' that pass the data to the views, which are just the templates.
In pyramid terms, 'Resources' are the 'models', and you are free to use wherever you want here, if you want an ORM you can use SQLAlchemy for example or mongodb or wherever.
The framework itself functions as the 'controllers', and the actions are called 'views' this can be normal functions or classes, you are free to organize them wherever you like. This views may use a template and a renderer to construct the response that is send to the browser.
Hope it helps (please excuse my bad english)