塔“全局名称”c“未定义”
我已经安装了 Pylons v0.9.7,并使用 genshi 创建了一个项目。 我尝试编写一个简单的测试用例,但它不起作用。
代码: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
请帮我找到错误。
i had setup Pylons v0.9.7, and created a project using genshi.
I tried to code an easy test case, but it is not working.
code: 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')
code: 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>
and Error message(on log)
Error - <type 'exceptions.NameError'>: global name 'c' is not defined
Please help me find the error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要定义名称
c
(全局或本地)。您永远不会定义名为c
的任何内容。因此,在将任何内容分配给
c.title
之前,请定义一个合适的名称c
(可以设置属性title
的名称!)!下一个提示:
from pylons import tmpl_context as c
- 你没有这样做,
from ... import ... as
,是吗?现在?-)requires name
c
to be defined (globally or locally). You never define anything namedc
.So, define a suitable name
c
(one where attributetitle
can be set!) before you assign anything toc.title
!Next hint:
from pylons import tmpl_context as c
-- you didn't do thatfrom ... import ... as
, did you now?-)