加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 金字塔“模型”也是金字塔“资源”吗?

发布时间:2020-12-16 22:25:13 所属栏目:Python 来源:网络整理
导读:我目前正在学习如何使用Python Pyramid Web框架,并且发现文档非常出色. 然而,当涉及将“模型”(即在SQLAlchemy的声明系统下定义的类)与“资源”的概念(即在视图上定义访问控制列表的方法)区分开来时,我遇到了绊脚石.用于Pyramid的auth系统). 我理解上面的陈

我目前正在学习如何使用Python Pyramid Web框架,并且发现文档非常出色.

然而,当涉及将“模型”(即在SQLAlchemy的声明系统下定义的类)与“资源”的概念(即在视图上定义访问控制列表的方法)区分开来时,我遇到了绊脚石.用于Pyramid的auth系统).

我理解上面的陈述似乎表明我已经理解了差异,但我无法理解我是否应该创建模型资源(通过直接在模型类中添加__acl__属性)或创建一个单独的资源类(具有正确的__parent__和__name__属性),表示对使用该模型的视图的访问.

任何指导表示赞赏.

最佳答案
如果应用程序的域模型是分层次的,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.

摘自Resources

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 Auth Demo

我的拙见:您不需要完全理解这两个概念,也不需要为您的第一个项目采用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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读