0

我正在与viewlets. 我的想法是用我自己的徽标、菜单、地址栏等内容覆盖默认的克隆站点。viewlet我在自己的createPictMenu.py文件中使用了默认代码。里面的代码brundelre3/eggs/plone.app.layout-2.3.4-py2.7.egg/plone/app/layout/viewlets/common.py ->class LogoViewlet(ViewletBase):

我的 createPictMenu.py 看起来像这样

class bdrMenuView(LogoViewlet):
    template = ViewPageTemplateFile('templates/main_page.pt')

    def __init__(self, context, request, view, manager=None):
        super(ViewletBase, self).__init__(context, request)
        self.__parent__ = view
        self.context = context
        self.request = request
        self.view = view
        self.manager = manager

    def main_page(self):
        return self.template()

这里 LogoViewlet 是我从鸡蛋文件夹下的 common.py 继承的类。它成功地用我的菜单替换了 plone.logo。我在下面看到了localhost:8086/brundelre3/@@manage-viewlets

但是当我运行我的项目时,localhost:8086/brundelre3/main_page.html它显示错误

错误信息 :

2013-08-14 11:18:19 ERROR Zope.SiteErrorLog 1376459299.050.254417887359 http://localhost:8086
/brundelre3/main_page.html
Traceback (innermost last):
Module ZPublisher.Publish, line 115, in publish
Module ZPublisher.BaseRequest, line 501, in traverse
Module ZPublisher.BaseRequest, line 346, in traverseName
Module ZPublisher.BaseRequest, line 116, in publishTraverse
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 least 4 arguments (3 given)

谁能告诉这段代码有什么问题?

4

1 回答 1

1

我看到了一些问题,但如果没有更多信息,很难确切知道是哪一个导致了这个错误。我的猜测是,当它应该传递参数时,它super没有传递参数。view我相信这里也有一个错字(应该是super(bdrMenuView, self),不是super(ViewletBase, self))。

试试这个修订版:

class bdrMenuView(LogoViewlet):
    template = ViewPageTemplateFile('templates/main_page.pt')

    def __init__(self, context, request, view, manager=None):
        super(bdrMenuView, self).__init__(context, request, view)
        self.__parent__ = view
        self.context = context
        self.request = request
        self.view = view
        self.manager = manager

    def main_page(self):
        return self.template()
于 2016-07-28T20:13:40.963 回答