Python 塔架Mako未定义变量
在控制器中,我定义了两种方法: foobar.py:Python 塔架Mako未定义变量,python,pylons,mako,Python,Pylons,Mako,在控制器中,我定义了两种方法: 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} 这给了我一个错误==>AttributeError:'ContextObj'对象没有属性'help\u text' 在阅读了一些mako
class foo(self):
c.help_text = 'help'
return render('/index.html')
class bar(self):
return render('/index.html')
index.html:
${c.help_text}
这给了我一个错误==>AttributeError:'ContextObj'对象没有属性'help\u text'
在阅读了一些mako文档后,我尝试:
% if c.help_text is UNDEFINED:
foo
% else:
${c.help_text}
% endif
这也给了我一个错误。然后在我的development.ini中,我提出:
mako.strict_undefined = false
之后
这仍然给我一个错误==>AttributeError:“ContextObj”对象没有属性“help\u text”我认为您的控制器代码不正确。您的第一个样本应该是
def foo(request):
c.help_text = 'help'
return render('/index.html')
def bar(request):
return render('/index.html')
……或者
class Controller(object):
def foo(self, request):
c.help_text = 'help'
return render('/index.html')
def bar(self, request):
return render('/index.html')
我相信,因为您的控制器代码不正确,“c.help_text”实际上不是为了响应查询而运行的,而是在启动应用程序时正确处理的
如果您修复了这些错误,但仍然存在问题,请提供有关错误的更多信息?您是否有堆栈跟踪或确切的行号?我认为您的控制器代码不正确。您的第一个样本应该是
def foo(request):
c.help_text = 'help'
return render('/index.html')
def bar(request):
return render('/index.html')
……或者
class Controller(object):
def foo(self, request):
c.help_text = 'help'
return render('/index.html')
def bar(self, request):
return render('/index.html')
我相信,因为您的控制器代码不正确,“c.help_text”实际上不是为了响应查询而运行的,而是在启动应用程序时正确处理的
如果您修复了这些错误,但仍然存在问题,请提供有关错误的更多信息?您是否有堆栈跟踪或精确的行号?请参阅此问题:请参阅此问题: