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

python– 金字塔“模型”也是金字塔“资源”吗?,第1张

概述我目前正在学习如何使用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
> @L_301_4@
> 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.

总结

以上是内存溢出为你收集整理的python – 金字塔“模型”也是金字塔“资源”吗?全部内容,希望文章能够帮你解决python – 金字塔“模型”也是金字塔“资源”吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1205964.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存