gpt4 book ai didi

python - Pylons Mako undefined variable

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:23 25 4
gpt4 key购买 nike

在 Controller 中,我定义了 2 个方法:

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' object has no attribute 'help_text'

阅读一些 mako 文档后,我尝试:

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

它也给我一个错误。然后在我的 development.ini 中,我输入:

mako.strict_undefined = false

之后

[app:main]

这仍然给我一个错误 ==> AttributeError: 'ContextObj' object has no attribute 'help_text'

最佳答案

我认为您的 Controller 代码不正确。您的第一个样本应该是...

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')

我相信因为您的 Controller 代码不正确,“c.help_text”实际上并没有运行以响应处理查询,而是在您启动应用程序时立即处理。

如果您修复了这些错误但问题仍然存在,能否请您提供有关该错误的更多信息?您有堆栈跟踪或确切的行号吗?

关于python - Pylons Mako undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12008767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com