views:

277

answers:

1

hiyas.

i had setup Pylons v0.9.7, and create project. and using genshi. and i coding to easy test code , but that code dont 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"&gt;
<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 teach where of this code the problem is. When this English is not unskillfully read easily, I'm sorry. thanks.

+3  A: 
    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?-)

Alex Martelli
Giving is a light as for the hint. I have your book(python CookBook)!I am very honored. Hereafter, it tries again.
Schaft
Ahhh! it worked! thanks Alex!i understand "C was tmpl_context".I wish sincerely to express our gratitude.
Schaft