I've been using a simple grok and Plone 4.1.4. So far I tried known good configuration for version 1.2.0 and 1.1.1 taken from here five.grok

I attempt to use grok.View with redirects, and whenever redirect code (self.redirect('url')) is run, the following TypeError is raised:

TypeError: redirect() got an unexpected keyword argument 'trusted'
> /home/alex/projects/eggs/grokcore.view-1.13.5-py2.6.egg/grokcore/view/components.py(50)redirect()
-> url, status=status, trusted=trusted)

I found this discussion that deals with similar problem but no real solution. gmane

It's really easy to reproduce the error, just have an update method in grok.View-derived class.

from five import grok
from Products.CMFCore.interfaces import ISiteRoot
class RedirectTest(grok.View):
    grok.context(ISiteRoot)
    grok.require('zope2.View')
    grok.name('testredirect')
    def update(self):
        self.redirect(self.url(''))
    def render(self):
        self.redirect(self.url(''))
有帮助吗?

解决方案

To use Grok on the Zope2 platform (used by Plone), you need to install the correct version of the five.grok package.

Grok is developed against the Zope Toolkit, and the publisher package in the ZTK has a slightly different API than what the Zope2 publisher offers. five.grok bridges that difference. But you need to have the right version to make the correct match.

For Plone 4.1 (Zope 2.13), make sure you use five.grok version 1.3.1 or newer:

  • Fix the redirect method to properly work. Unlike in Zope 3, it doesn't support trusted.

If you were to upgrade to Plone 4.2, the right version pin is included in the included versions.cfg file.

其他提示

Martijn's answer is the most correct. However, as workaround, if you cannot upgrade your five.grok version in your production environment to >= 1.3.1, you can use "self.request.response.redirect(url_string)" instead of "self.redirect(url_string)". It's so ugly, I know, and I recommend to use this alternative only under this condition.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top