Error using pylon redirection

Using Pylons verson 1.0: Working on a FormDemo example from a 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.'

At first, I noticed that in the book, the author points to the redirect_to import to perform the following import:

from pylons.controllers.util import redirect_to

This seems wrong, since redirect_to lives in the routes module, so I changed it to this:

from routes import redirect_to

everything works fine, the import error no longer occurs, but when I submit the form, I see the following trace


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 anybody help me?

+3
source share
1 answer

Try:

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

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

Pylons 1.0 documentation QuickWiki, 1.0, .

+6

Source: https://habr.com/ru/post/1755234/


All Articles