2010-07-19 95 views
3

使用塔VERSON 1.0: 从主塔书上的FormDemo例如工作:错误挂架重定向

http://pylonsbook.com/en/1.1/working-with-forms-and-validators.html

我的控制器具有以下功能:

class FormtestController(BaseController): 

    def form(self): 
     return render('/simpleform.html') 

    def submit(self): 
     # Code to perform some action based on the form data 
     # ... 
     h.redirect_to(controller='formtest', action='result') 

    def result(self): 
     return 'Your data was successfully submitted.' 

首先,我注意到在书中作者指出要导入redirect_to执行以下导入:

from pylons.controllers.util import redirect_to 

这似乎是不正确的,因为redirect_to的生活路由模块,所以我把它改成这样:

from routes import redirect_to 

一切正常,没有更多的进口错误,但是当我执行一个表单提交,我看到了以下回溯


h.redirect_to(controller='formtest', action='result') 
target = url_for(*args, **kargs) 
encoding = config.mapper.encoding 
return getattr(self.__shared_state, name) 
AttributeError: 'thread._local' object has no attribute 'mapper' 

谁能帮助我?

回答

6

尝试:

from pylons import url 
from pylons.controllers.util import redirect 

# ... 
redirect(url(controller='formtest', action='result')) 

你可能会更好使用当前Pylons 1.0 documentation和更新的1.0 QuickWiki tutorial,网站上的其他参考资料之一。

+1

为了说明,支持redirect_to(和url_for)已在Pylons 0.97中弃用,并在Pylons 1.0中删除。 The Pylons book based on 0.97,所以你可能想要阅读http://pylonshq.com/docs/en/1.0/upgrading/ – 2010-07-19 22:33:30

+0

QuickWiki页面实际上并没有完全更新为Pylons 1.0(它甚至引用了0.97几个地方)。最好的办法是松松地遵循指示,同时查看从bitbucket中提取的quickwiki源代码 - 该工具适用于1.0。 – rfusca 2010-07-20 17:10:25

+0

这真的很让人讨厌,这本应该涵盖1.1的书基于0.97 – qliq 2011-11-10 02:53:31