パイロン「グローバルネーム「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
エラーを見つけるのを手伝ってください。
解決
c.title="title"
名前が必要です c
定義する(グローバルまたはローカル)。あなたは決して定義しません なんでも 名前が付けられました c
.
したがって、適切な名前を定義します c
(属性 title
あなたが何かを割り当てる前に、設定することができます!) c.title
!
次のヒント: from pylons import tmpl_context as c
- あなたはしませんでした 行う それ from ... import ... as
, 、あなたは今ですか? - )
所属していません StackOverflow