簡體   English   中英

定向塔馬科不確定變量

[英]Pylons Mako undefined variable

在控制器中,我定義了2種方法:

foob​​ar.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_text'

閱讀一些mako文檔后,我嘗試:

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

這也給我一個錯誤。 然后在我的development.ini中,輸入:

mako.strict_undefined = false

[app:main]

這仍然給我一個錯誤==> AttributeError:'ContextObj'對象沒有屬性'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”,但是在啟動應用程序時就可以正確地對其進行處理。

如果您糾正了這些錯誤,但仍然遇到問題,請您提供更多有關該錯誤的信息? 您有堆棧跟蹤或確切的行號嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM