将新视图添加到 Dexterity 类型会导致“找不到页面”查看项目

发布于 12-12 06:01 字数 2156 浏览 1 评论 0原文

我正在阅读最近的《Professional Plone 4 Development》一书,关于 Plone 4.1.2 安装。

我已通过 Dexterity 成功定义了内容类型,现在正在尝试为其中一种类型创建自定义视图。架构和视图的定义如下:

from zope import schema
from plone.directives import form
from five import grok
from ctcc.contenttypes import CTCCTypesMessageFactory as _

class ITrial(form.Schema):
    """A clinical trial."""

    title = schema.TextLine(
        title = _(u'label_title', default=u'Title'),
        required = True,
    )

    description = schema.Text(
        title=_(u'label_description', default=u'Description'),
        description = _(u'help_description', default=u'A short summary of the content'),
        required = False,
        missing_value = u'',
    )

class View(grok.View):
    grok.context(ITrial)
    grok.require('zope2.View')
    grok.name('view')

以下是类型 FTI 的相关部分: 看法 错误的

<alias from="(Default)" to="(selected layout)"/>
<alias from="edit" to="@@edit"/>
<alias from="sharing" to="@@sharing"/>
<alias from="view" to="@@view"/>

<action title="View" action_id="view" category="object" condition_expr=""
    url_expr="string:${folder_url}/" visible="True">
    <permission value="View"/>
</action>

模板本身位于 ctcc.contenttypes/Trial_templates/view.pt 中,它应该只显示标题和内容。描述:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="context/main_template/macros/master"
      i18n:domain="ctcc.contenttypes">
<body>

<metal:content-core fill-slot="content-core">
    <metal:content-core define-macro="content-core">

        <div tal:replace="structure context/text/output" />

    </metal:content-core>
</metal:content-core>

</body>
</html>

在所有这些都已到位的情况下访问该类型的任何实例都会导致“找不到页面”错误。似乎没有什么东西将新视图与预期路径联系起来,但由于这是我使用 Plone 的第一周,我不知道从哪里开始追踪这一点。我也没有看到在前台模式下运行该网站时出现错误。

任何帮助将不胜感激。

I'm working through the recent Professional Plone 4 Development book, on a Plone 4.1.2 install.

I have successfully defined the content types via Dexterity and am now trying to create a custom view for one of the types. The schema & view are defined as such:

from zope import schema
from plone.directives import form
from five import grok
from ctcc.contenttypes import CTCCTypesMessageFactory as _

class ITrial(form.Schema):
    """A clinical trial."""

    title = schema.TextLine(
        title = _(u'label_title', default=u'Title'),
        required = True,
    )

    description = schema.Text(
        title=_(u'label_description', default=u'Description'),
        description = _(u'help_description', default=u'A short summary of the content'),
        required = False,
        missing_value = u'',
    )

class View(grok.View):
    grok.context(ITrial)
    grok.require('zope2.View')
    grok.name('view')

Here is the relevant section from the type's FTI:
view
False

<alias from="(Default)" to="(selected layout)"/>
<alias from="edit" to="@@edit"/>
<alias from="sharing" to="@@sharing"/>
<alias from="view" to="@@view"/>

<action title="View" action_id="view" category="object" condition_expr=""
    url_expr="string:${folder_url}/" visible="True">
    <permission value="View"/>
</action>

And the template itself, located in ctcc.contenttypes/trial_templates/view.pt, which should simply display the title & description:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="context/main_template/macros/master"
      i18n:domain="ctcc.contenttypes">
<body>

<metal:content-core fill-slot="content-core">
    <metal:content-core define-macro="content-core">

        <div tal:replace="structure context/text/output" />

    </metal:content-core>
</metal:content-core>

</body>
</html>

Accessing any instances of the type with all this in place causes a "page not found" error. Something doesn't seem to be tying up the new view to the expected path, but as this is my first week with Plone I've no idea where to begin to track this down. I'm seeing no errors running the site in foreground mode either.

Any help whatsoever would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你到最终2024-12-19 06:01:21

您是否在 setup.py 中包含了依赖项?

install_requires=[
  'setuptools',
  'plone.app.dexterity',
  ...
  ],

你在configure.zcml中初始化了Grok吗?

<configure
  xmlns="http://namespaces.zope.org/zope"
  ...
  xmlns:grok="http://namespaces.zope.org/grok">

  <includeDependencies package="." />
  <grok:grok package="." />
  ...

</configure>

您是否在您的metadata.xml 中包含了Dexterity 的GenericSetup 配置文件?

<metadata>
 <version>1</version>
 <dependencies>
  <dependency>profile-plone.app.dexterity:default</dependency>
 </dependencies>
</metadata>

did you included the dependency in setup.py?

install_requires=[
  'setuptools',
  'plone.app.dexterity',
  ...
  ],

did you initialized Grok in your configure.zcml?

<configure
  xmlns="http://namespaces.zope.org/zope"
  ...
  xmlns:grok="http://namespaces.zope.org/grok">

  <includeDependencies package="." />
  <grok:grok package="." />
  ...

</configure>

did you included Dexterity's GenericSetup profile in your metadata.xml?

<metadata>
 <version>1</version>
 <dependencies>
  <dependency>profile-plone.app.dexterity:default</dependency>
 </dependencies>
</metadata>
倚栏听风2024-12-19 06:01:21

问题出在模板中的这一行:

<div tal:replace="structure context/text/output" />

我已将示例模板剥离到我认为的最低限度。感谢 David Glick 的建议,我从 error_log 中的忽略异常列表中删除了 NotFound 并看到了以下内容:

  Module Products.PageTemplates.Expressions, line 225, in evaluateText
  Module zope.tales.tales, line 696, in evaluate
   - URL: /opt/plone41/zeocluster/src/ctcc.contenttypes/ctcc/contenttypes/trial_templates/view.pt
   - Line 13, Column 8
   - Expression: <PathExpr standard:u'context/text/output'>
  [...]
  Module OFS.Traversable, line 299, in unrestrictedTraverse
   - __traceback_info__: ([], 'text')
NotFound: text

现在我可以看到导致问题的原因,并开始更深入地阅读TALs,我知道它失败的原因:正如怀疑的那样,我的无知。

谢谢大家!

The problem was with this line in the template:

<div tal:replace="structure context/text/output" />

I had stripped back an example template to what I thought was the bare minimum. Thanks to David Glick's suggestion, I removed NotFound from the ignored exceptions list in error_log and saw the following:

  Module Products.PageTemplates.Expressions, line 225, in evaluateText
  Module zope.tales.tales, line 696, in evaluate
   - URL: /opt/plone41/zeocluster/src/ctcc.contenttypes/ctcc/contenttypes/trial_templates/view.pt
   - Line 13, Column 8
   - Expression: <PathExpr standard:u'context/text/output'>
  [...]
  Module OFS.Traversable, line 299, in unrestrictedTraverse
   - __traceback_info__: ([], 'text')
NotFound: text

Now that I can see what's causing the problem and have started reading deeper into TALs, I can see why it's failing: ignorance on my behalf, as suspected.

Thanks, everyone!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文