塔“全局名称”c“未定义”

发布于 2024-08-17 12:10:56 字数 896 浏览 6 评论 0原文

我已经安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兮颜 2024-08-24 12:10:56
    c.title="title"

需要定义名称c(全局或本地)。您永远不会定义名为 c任何内容。

因此,在将任何内容分配给 c.title 之前,请定义一个合适的名称 c(可以设置属性 title 的名称!)!

下一个提示:from pylons import tmpl_context as c - 你没有这样做,from ... import ... as,是吗?现在?-)

    c.title="title"

requires name c to be defined (globally or locally). You never define anything named c.

So, define a suitable name c (one where attribute title can be set!) before you assign anything to c.title!

Next hint: from pylons import tmpl_context as c -- you didn't do that from ... import ... as, did you now?-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文