GoogleAppEngineのテンプレートに値を受け渡す
デザインとロジックの分離が、テンプレートを使用する最大のメリットです。
main.py側に値を用意して、それをテンプレート側に渡してみましょう。
main.pyの修正
main.py
class MainHandler(webapp.RequestHandler): def get(self): text = 'hogehoge' date = '2010/08/03' list = {'text': text, 'date': date} fpath = os.path.join(os.path.dirname(__file__), 'templates', 'index.html') html = template.render(fpath, list) self.response.out.write(html)
テンプレートファイルの修正
templates/index.html
<body> <h1>Sample Page</h1> <div>{{text}}</div> <div>{{date}}</div> </body>