在Pylons中重定向时出错
使用Pylons 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_to,你需要执行以下导入:
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'
有人能帮我吗?
1 个回答
6
试试这个:
from pylons import url
from pylons.controllers.util import redirect
# ...
redirect(url(controller='formtest', action='result'))
你可以看看现在的 Pylons 1.0 文档 和为 1.0 更新的 QuickWiki 教程,还有网站上的其他参考资料,这样可能会更好。