使用Pylons verson 1.0: 使用Pylons书中的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_来执行以下导入:
from pylons.controllers.util import redirect_to
这似乎是不正确的,因为redirect_to存在于routes模块中,所以我将其更改为:
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'
任何人都可以帮助我吗?
答案 0 :(得分:6)
尝试:
from pylons import url
from pylons.controllers.util import redirect
# ...
redirect(url(controller='formtest', action='result'))
您可能最好使用当前的Pylons 1.0 documentation和QuickWiki tutorial更新的1.0,以及网站上的其他参考资料。