金字塔 "model" 也是金字塔 "resource" 吗?
Is a Pyramid "model" also a Pyramid "resource"?
我目前正在学习如何使用 Python Pyramid 网络框架,并且发现文档非常出色。
然而,在区分 "model" 的想法(即在 SQLAlchemy 的声明系统下定义的 class 的想法与 [=24 的想法时,我遇到了绊脚石=](即一种在视图上定义访问控制列表以供 Pyramid 的身份验证系统使用的方法)。
我理解上面的陈述似乎表明我已经理解了差异,但是我很难理解我是否应该制作模型资源(通过直接在模型中添加 __acl__
属性 class) 或创建一个单独的资源 class(它具有适当的 __parent__
和 __name__
属性)代表对使用该模型的视图的访问。
感谢任何指导。
I'm having trouble understanding whether I should be making models resources (by adding the acl attribute directly in the model class) or creating a separate resource class
答案取决于您想要的耦合程度。对于一个简单的应用程序,为了简单起见,我建议制作模型资源。但是对于高内聚低耦合的复杂应用程序,最好将模型与资源分离。
如果一个应用程序的域模型是分层的,Pyramid 提供了资源的想法来构建资源树。遍历用于将 URL 映射到代码并标识资源树中的资源。在使用关系数据库时,您通常不使用资源和遍历。
摘自"Defending the design - Pyramid Does Traversal, and I Don't Like Traversal"
In Pyramid, traversal is the act of resolving a URL path to a resource object in a resource tree. Some people are uncomfortable with this notion, and believe it is wrong. Thankfully if you use Pyramid and you don't want to model your application in terms of a resource tree, you needn't use it at all. Instead use URL dispatch to map URL paths to views.
Relational databases aren't naturally hierarchical, so traversing one like a tree is not possible.
You can be assured that if you don't want to understand traversal, you don't have to. You can happily build Pyramid applications with only URL dispatch.
A resource is an object that represents a "place" in a tree related to
your application. (...) A resource tree is a set of nested
dictionary-like objects which you can use to represent your website's
structure.
In an application which uses traversal to map URLs to code, the
resource tree structure is used heavily to map each URL to a view
callable. When traversal is used, Pyramid will walk through the
resource tree by traversing through its nested dictionary structure in
order to find a context resource. Once a context resource is found,
the context resource and data in the request will be used to find a
view callable.
In an application which uses URL dispatch, the resource tree is only
used indirectly, and is often "invisible" to the developer. (...) This root resource sometimes has security
declarations attached to it, but is not required to have any. In
general, the resource tree is much less important in applications that
use URL dispatch than applications that use traversal.
我认为该主题已在文档中广泛涵盖。
我曾经推荐过一个项目来强调 Pyramid 的功能。
我的愚见:你不需要完全和预先理解这两个概念来为你的第一个项目采用 Pyramid 框架。使用关系数据库时,请使用 URL Dispatch 和 SQLAlchemy。
Excerpt - Pyramid Provides Too Many "Rails"
By design, Pyramid is not a particularly opinionated web framework. Pyramid provides some features that other web frameworks do not. These are features meant for use cases that might not make sense to you if you're building a simple (...) web application.
我目前正在学习如何使用 Python Pyramid 网络框架,并且发现文档非常出色。
然而,在区分 "model" 的想法(即在 SQLAlchemy 的声明系统下定义的 class 的想法与 [=24 的想法时,我遇到了绊脚石=](即一种在视图上定义访问控制列表以供 Pyramid 的身份验证系统使用的方法)。
我理解上面的陈述似乎表明我已经理解了差异,但是我很难理解我是否应该制作模型资源(通过直接在模型中添加 __acl__
属性 class) 或创建一个单独的资源 class(它具有适当的 __parent__
和 __name__
属性)代表对使用该模型的视图的访问。
感谢任何指导。
I'm having trouble understanding whether I should be making models resources (by adding the acl attribute directly in the model class) or creating a separate resource class
答案取决于您想要的耦合程度。对于一个简单的应用程序,为了简单起见,我建议制作模型资源。但是对于高内聚低耦合的复杂应用程序,最好将模型与资源分离。
如果一个应用程序的域模型是分层的,Pyramid 提供了资源的想法来构建资源树。遍历用于将 URL 映射到代码并标识资源树中的资源。在使用关系数据库时,您通常不使用资源和遍历。
摘自"Defending the design - Pyramid Does Traversal, and I Don't Like Traversal"
In Pyramid, traversal is the act of resolving a URL path to a resource object in a resource tree. Some people are uncomfortable with this notion, and believe it is wrong. Thankfully if you use Pyramid and you don't want to model your application in terms of a resource tree, you needn't use it at all. Instead use URL dispatch to map URL paths to views.
Relational databases aren't naturally hierarchical, so traversing one like a tree is not possible.
You can be assured that if you don't want to understand traversal, you don't have to. You can happily build Pyramid applications with only URL dispatch.
A resource is an object that represents a "place" in a tree related to your application. (...) A resource tree is a set of nested dictionary-like objects which you can use to represent your website's structure.
In an application which uses traversal to map URLs to code, the resource tree structure is used heavily to map each URL to a view callable. When traversal is used, Pyramid will walk through the resource tree by traversing through its nested dictionary structure in order to find a context resource. Once a context resource is found, the context resource and data in the request will be used to find a view callable.
In an application which uses URL dispatch, the resource tree is only used indirectly, and is often "invisible" to the developer. (...) This root resource sometimes has security declarations attached to it, but is not required to have any. In general, the resource tree is much less important in applications that use URL dispatch than applications that use traversal.
我认为该主题已在文档中广泛涵盖。
我曾经推荐过一个项目来强调 Pyramid 的功能。
我的愚见:你不需要完全和预先理解这两个概念来为你的第一个项目采用 Pyramid 框架。使用关系数据库时,请使用 URL Dispatch 和 SQLAlchemy。
Excerpt - Pyramid Provides Too Many "Rails"
By design, Pyramid is not a particularly opinionated web framework. Pyramid provides some features that other web frameworks do not. These are features meant for use cases that might not make sense to you if you're building a simple (...) web application.