2

In the controller, I define 2 method:

foobar.py:

class foo(self):
    c.help_text = 'help'
    return render('/index.html')

class bar(self):
    return render('/index.html')

index.html:

${c.help_text}

This gives me an error ==> AttributeError: 'ContextObj' object has no attribute 'help_text'

After reading some mako docs, I try:

    % if c.help_text is UNDEFINED:
        foo
    % else:
        ${c.help_text}
    % endif

It also gives me an error. Then in my development.ini, I put:

mako.strict_undefined = false

after

[app:main]

This still give me an error ==> AttributeError: 'ContextObj' object has no attribute 'help_text'

Mark Hildreth
  • 42,023
  • 11
  • 120
  • 109
Faris Nasution
  • 3,450
  • 5
  • 24
  • 29
  • see this question: http://stackoverflow.com/questions/12006720/pylons-mako-how-to-check-if-variable-exist-or-not – Sam Watkins Apr 29 '15 at 07:30

1 Answers1

0

I believe your controller code is incorrect. Your first sample should either be...

def foo(request):
    c.help_text = 'help'
    return render('/index.html')

def bar(request):
    return render('/index.html')

...or...

class Controller(object):
    def foo(self, request):
        c.help_text = 'help'
        return render('/index.html')

    def bar(self, request):
        return render('/index.html')

I believe that because you have this controller code incorrect, the "c.help_text" is not actually being run in response to handling a query, but it's being handled right when you start up the application.

If you fix these errors and still have issues, can you please provide more information the error? Do you have a stack trace or an exact line number?

Mark Hildreth
  • 42,023
  • 11
  • 120
  • 109