0

假设我有一个包含以下类的示例应用程序:

##
## impelementation/SampleApp.py
##
class SampleApp: # inherits from required classes
    """ """
    implements(ISampleApp)
    # ...
    index_html = PageTemplateFile('templates/index.pt')


##
## implementation/SampleAppUser.py
##
class SampleAppUser: # inherits from required classes
    """ """
    implements(ISampleAppUser)
    # ...
    index_html = PageTemplateFile('templates/user_index.pt')

manage_addSampleAppUserForm = PageTemplateFile('manage_addSampleUserUserForm.pt')

现在我希望能够从应用程序中的任何位置manage_addSampleUserUserForm.pt链接到登录表单 ( ) ,包括其索引页 ( )。index.pt

我尝试了以下方法,但它不起作用:

index.pt

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns="http://xml.zope.org/namespaces/tal">
  <head><title>SampleApp</title></head>
  <body>
     <h2>Title</h2><hr/>
     <a href="#" title="Sign In"
         tal:attributes="href here/signin.html">Sign In</a>
  </body>
</html>

configure.zcml

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

  <five:registerPackage package="." initialize=".initialize" />

  <browser:page
          name="signin.html"
          class="bahmanm.sampleapp.implementation.SampleAppUser.SampleAppUser"
          template="templates/manage_addSampleUserForm.pt"
          permission="zope.Public"
  />

</configure>

在实例启动期间,Zope 抱怨:

ZopeXMLConfigurationError: File "/home/bahman/sampleapp/sampleapp.devistan/src/bahmanm/sampleapp/configure.zcml", line 10.2-15.5
    TypeError: page() takes at least 4 arguments (5 given)

我也尝试添加for="*",但 Zope 在导航到应用程序索引页面时弹出以下错误:

2013-01-08 15:43:26 ERROR Zope.SiteErrorLog 1357647206.080.27220840385 http://localhost:8080/sampleapp/index_html
Traceback (innermost last):
  Module ZPublisher.Publish, line 126, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 46, in call_object
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.PageTemplates.PageTemplateFile, line 130, in _exec
  Module Products.PageTemplates.PageTemplate, line 79, in pt_render
  Module zope.pagetemplate.pagetemplate, line 113, in pt_render
  Module zope.tal.talinterpreter, line 271, in __call__
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 405, in do_startTag
  Module zope.tal.talinterpreter, line 482, in attrAction_tal
  Module Products.PageTemplates.Expressions, line 225, in evaluateText
  Module zope.tales.tales, line 696, in evaluate
   - URL: index_html
   - Line 7, Column 3
   - Expression: <PathExpr standard:'here/signin.html'>
   - Names:
      {'container': <SampleApp at /sampleapp>,
       'context': <SampleApp at /sampleapp>,
       'default': <object object at 0x7fa1499cf4c0>,
       'here': <SampleApp at /sampleapp>,
       'loop': {},
       'nothing': None,
       'options': {'args': ()},
       'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0x7fa134030ba8>,
       'request': <HTTPRequest, URL=http://localhost:8080/sampleapp/index_html>,
       'root': <Application at >,
       'template': <PageTemplateFile at /sampleapp/index>,
       'user': <User 'admin'>}
  Module zope.tales.expressions, line 217, in __call__
  Module Products.PageTemplates.Expressions, line 147, in _eval
  Module zope.tales.expressions, line 124, in _eval
  Module Products.PageTemplates.Expressions, line 74, in boboAwareZopeTraverse
  Module OFS.Traversable, line 317, in restrictedTraverse
  Module OFS.Traversable, line 275, in unrestrictedTraverse
   - __traceback_info__: ([], 'signin.html')
  Module zope.component._api, line 120, in queryMultiAdapter
  Module zope.component.registry, line 238, in queryMultiAdapter
  Module zope.interface.adapter, line 532, in queryMultiAdapter
TypeError: __init__() takes at most 2 arguments (3 given)

我究竟做错了什么?老实说,我相信我做错了很多事情 :-) 因为我只是盲目地阅读Zope 3 apidoc和阅读其他产品的代码(如 SilvaForum)。

我真的很感激任何提示/帮助。TIA,

4

1 回答 1

1

浏览器页面完全是独立的组件。它们不是目标内容类型的一部分,而是完全独立的组件。

如果您只需要一个模板(没有视图),只需完全省略 class 指令:

<browser:page
    name="signin.html"
    for="*"
    template="templates/manage_addSampleUserForm.pt"
    permission="zope.Public"
    />

无需为此PageTemplateFile手动创建实例。

目前尚不清楚您想对模板中的链接做什么。`here/signin.html"看起来不像是一个有效的 TALES 表达式。在普通的 Zope 中,没有简单的工具可以生成相对于站点根目录的绝对 URL。也许您只是想要/signin.html而不使用 TAL 表达式?

于 2013-01-08T12:40:58.103 回答