Error using redirect in pylons
Using Pylons verson 1.0: Working on the FormDemo example from the Pylons book:
http://pylonsbook.com/en/1.1/working-with-forms-and-validators.html
My controller has the following functions:
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='for开发者_开发知识库mtest', action='result')
def result(self):
return 'Your data was successfully submitted.'
First I noticed that in the book the author indicates to import redirect_to you executing the following import:
from pylons.controllers.util import redirect_to
This seems to be incorrect, as redirect_to lives in the routes module so I changed it to this:
from routes import redirect_to
everything works fine, no more import error, but when I execute a form submit, i see the following traceback
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'
can anyone help me?
Try:
from pylons import url
from pylons.controllers.util import redirect
# ...
redirect(url(controller='formtest', action='result'))
You might be better off using the current Pylons 1.0 documentation and the QuickWiki tutorial updated for 1.0, among other references on the site.
精彩评论