我目前正在学习如何使用Python Pyramid Web框架,并且发现文档非常出色.
然而,当涉及将“模型”(即在sqlAlchemy的声明系统下定义的类)与“资源”的概念(即在视图上定义访问控制列表的方法)区分开来时,我遇到了绊脚石.用于Pyramid的auth系统).
我理解上面的陈述似乎表明我已经理解了差异,但我无法理解我是否应该创建模型资源(通过直接在模型类中添加__acl__属性)或创建一个单独的资源类(具有正确的__parent__和__name__属性),表示对使用该模型的视图的访问.
任何指导表示赞赏.
摘自“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.
> Resources
> Much ado about traversal
> Traversal
> Combining Traversal and URL Dispatch
我过去常常推荐一个强调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.