Zope 2:如何正确地“浏览器:页面”使页面随处可用?

时间:2013-01-08 12:19:15

标签: zope

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

##
## 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)。< / p>

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

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并阅读其他产品的代码(如席尔瓦福尔斯)来盲目拍摄。

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

1 个答案:

答案 0 :(得分:1)

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

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

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

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

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