2012-08-17 8 views
2

정의되지 않은 2 방법파일론 마코, I 정의 제어기 가변

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

+0

이 질문 참조 : http://stackoverflow.com/questions/12006720/pylons-mako-how-to-check-if-variable-exist-or-not –

답변

0

귀하의 컨트롤러 코드가 잘못되었다고 생각합니다. 첫 번째 샘플 중 하나를 ... ...

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는"실제로 아니라고 생각 쿼리 처리에 대한 응답으로 실행되지만 응용 프로그램을 시작할 때 바로 처리됩니다.

이러한 오류를 수정했지만 여전히 문제가있는 경우 오류에 대한 자세한 정보를 제공해주십시오. 스택 추적 또는 정확한 회선 번호를 갖고 있습니까?