题
我已经设置了塔架V0.9.7,并使用Genshi创建了一个项目。我试图编码一个简单的测试用例,但它不起作用。
代码:会员
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
请帮助我找到错误。
解决方案
c.title="title"
需要名称 c
定义(全球或本地)。您永远不会定义 任何事物 命名 c
.
因此,定义一个合适的名字 c
(其中一个属性 title
可以设置!)在将任何内容分配给 c.title
!
下一个提示: from pylons import tmpl_context as c
- 你没有 做 那 from ... import ... as
, ,你现在吗? - )
不隶属于 StackOverflow