- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
创建 BrowserView 时在 Plone 中,我知道我可以选择使用 ZCML 配置模板,如下所示:
<configure
xmlns:browser="http://namespaces.zope.org/browser"
>
<browser:page
…
class=".foo.FooView"
template="foo.pt"
…
/>
</configure>
或者在代码中:
# foo.py
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.publisher.browser import BrowserPage
class FooView(BrowserPage):
"""
My View
"""
def __call__(self):
return ViewPageTemplateFile('foo.pt')(self)
这两种方法有什么区别吗?它们似乎都产生相同的结果。
子问题:我知道有一个可以导入的BrowserView
类,但通常每个人都使用BrowserPage
。如果两个类之间存在任何显着差异怎么办?
最佳答案
注意:要完全等同于 ZCML,您应该设置 index
变量来指定您正在使用的模板。这样 TTW 定制也将起作用。
# foo.py
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope.publisher.browser import BrowserPage
class FooView(BrowserPage):
index = ViewPageTemplateFile('foo.pt')
您可以在浏览器 View 中使用的另一种模式是添加更新方法。
class FooView(BrowserPage):
index = ViewPageTemplateFile('foo.pt')
def __call__(self):
self.update()
return self.index()
def update(self):
self.portal_catalog = ... # initialize code
但这不是问题。
那么有什么区别呢? 没有区别。浏览器 View 必须是可调用的。 ZCML 指令以对象具有索引的方式构建此可调用对象,该索引必须返回呈现的页面。
但是在每次调用时创建模板(你的例子)有一个区别:您在浏览器 View 的每次调用中都创建了一个新的模板实例。类变量不是这种情况。
最后一个选项:您不需要在指令中使用类参数
<configure xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
…
template="foo.pt"
…
/>
</configure>
有关更多信息,您应该阅读 the code of the directive ,它使用 SimpleViewClass where src is the template name .
关于python - ZCML 中的模板和 ViewPageTemplateFile 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13871915/
在我的一个项目的 buildout.cfg 文件中,我有这样的东西: [buildout] ... zcml = my.package plone.reload ... 一切正常,但我
ZCML 可以包含以下形式的条件指令 (conditional configuration directives) condition 的表达式语法是什么? ?是否允许使用“或”? 最佳答
我已经命名了实用程序,并希望标记名称以供以后使用 i18n。这是正确的方法吗? 最佳答案 实用程序的名称不是可翻译的消息 ID,而是内部技术 ID。您不能将其用于翻译目的。 如果您查看 zope.c
创建 BrowserView 时在 Plone 中,我知道我可以选择使用 ZCML 配置模板,如下所示: 或者在代码中: # foo.py from Products.Five.brow
我正在为我的 Plone 站点开发一个新的附加组件,结果它显示我的错误 configure.zcml : unbound prefix. 我在这里写我的 zcml 代码:
我想知道是否有其他人以前见过这个: 我有以下 ZCML: 当我尝试访问 siteroot/workflow_action 时,Plone 告诉我“这个页面似乎不存在......” 正在读取 ZCML
是否有一种方法可以在 grok.CodeView 类中标记可遍历的方法,就像使用 Zope 3 BrowserView 和 allowed_attributes ZCML 配置指令一样? 我找到了关于
我正在编写一个添加 View 适配器,并希望将其使用限制在特定权限范围内。 在 ZCML 中,我可以执行以下操作: 是否有 grok 等效的方法来做到这一点? 简单地使用 grok.re
在在 Plone 上,我有一个 permission属性。我可以在其中添加自定义权限,并在呈现浏览器 View 时具有更好的安全性。 只需添加 permission它起作用的属性:尝试执行@@m
我有一个带有以下 setup.py 的 Plone 插件 setup( ... install_requires=[ ... 'zope.i18n',
我有一个 python 类以 zope 3 zcml 的方式工作,但我想将 python 移动到一个独立的脚本中,可以通过 tal:content='context/get_tags' 的方式访问它。
我正在使用 paster 创建我的内容类型和 View 。我正在使用 Plone 3.3。 在我的 config.py 中: ADD_PERMISSIONS = { # -*- extra s
我是一名优秀的程序员,十分优秀!