开发者

Pylons "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(BaseContr开发者_StackOverflow中文版oller):

    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.


    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?-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜