2010-01-12 4 views
1

저는 Pylons v0.9.7을 설치했고 genshi를 사용하여 프로젝트를 만들었습니다. 쉬운 테스트 케이스를 작성하려고했지만 작동하지 않습니다.Pylons "글로벌 이름 'c'가 정의되지 않았습니다."

코드 : member.py

coding: utf-8 
import logging import foo.model 

from foo.lib.base import * 

log = logging.getLogger(__name__) 

class MemberController(BaseController): 

    def index(self): 
     c.title="title" 
     c.mes="message" 
     return render('test.html') 

코드 : test.html를

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns:py="http://genshi.edgewall.org/" 
     lang="ja"> 
    <head> 
     <title>${c.title}</title> 
    </head> 
<body> 
    <p>${c.mes}</p> 
</body> 
</html> 

및 오류 메시지 (로그에는)

Error - <type 'exceptions.NameError'>: global name 'c' is not defined 

나 오류를 찾을 수 있도록 도와주십시오.

답변

3
c.title="title" 

은 이름이 c (전역 또는 로컬)으로 정의되어야합니다. 을 정의하지 마십시오.c입니다.

c.title에 아무 것도 지정하기 전에 적절한 이름 인 c (하나의 속성이 title 인 경우!)을 정의하십시오!

다음 힌트 : from pylons import tmpl_context as c - 당신은 from ... import ... as가, 지금 한하지 않았다 -)

+1

기부가 힌트로 빛?. 나는 당신의 책 (파이썬 쿡북)을 가지고 있습니다! 매우 영광입니다. 이후에 다시 시도합니다. – Schaft

+0

아! 그것은 일했다! 감사합니다 알렉스! "C was tmpl_context"를 이해합니다. 감사의 말을 진심으로 바랍니다. – Schaft

관련 문제