tags:

views:

129

answers:

1

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='formtest', 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?

+2  A: 

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.

ars
To clarify, support for redirect_to (and url_for) has been deprecated in Pylons 0.97 and removed in Pylons 1.0. The Pylons book was based on 0.97, so you may want to read http://pylonshq.com/docs/en/1.0/upgrading/
Marius Gedminas
The QuickWiki page actually isn't fully updated for Pylons 1.0 either (it even references 0.97 in a few places). You're best bet is to kind of loosely follow the directions while looking at the quickwiki source pulled from bitbucket - which works for 1.0.
rfusca