0

in pylons, how do i use a variable that is considered global in a class, like using self, seems in pylons using self wont work.

suppose i have in controller :

a.py :

class AController(BaseController):

    def TestA(self):
        text = request.params.get('text', None) 
        self.text = text
        redirect(url(controller = 'A', action = 'TestB'))

    def TestB(self):
        render '%s' % self.text

got an error, 'AController' object has no attribute 'text', so how do i display 'text' or 'self.text' based on TestA using TestB in pylons

Faris Nasution
  • 3,450
  • 5
  • 24
  • 29

1 Answers1

0

I do something similar all the time with my pylons controller. The problem you are having is that if you call TestB first then self.text would never have been defined. All you need to do is define it first.

This is what I would do to make your example work:

class AController(BaseController):

    text = ''

    def TestA(self):
        text = request.params.get('text', None) 
        self.text = text
        redirect(url(controller = 'A', action = 'TestB'))

    def TestB(self):
        render '%s' % self.text
Mr-F
  • 871
  • 7
  • 12