Created
May 2, 2012 10:19
-
-
Save snaka/2575718 to your computer and use it in GitHub Desktop.
Jinja2でテンプレートに関数を埋め込む
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Hello, {{ hoge() }} san. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # coding: utf-8 | |
| import os | |
| import webapp2 | |
| from jinja2 import Environment, FileSystemLoader | |
| env = Environment(loader=FileSystemLoader(os.path.dirname(__file__))) | |
| env.globals['hoge'] = lambda: u"ほげほげ" | |
| class SecondHandler(webapp2.RequestHandler): | |
| def get(self): | |
| template = env.get_template('hello.html') | |
| self.response.out.write(template.render()) | |
| app = webapp2.WSGIApplication([('/', MainHandler), debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment