Skip to content

Instantly share code, notes, and snippets.

@snaka
Created May 2, 2012 10:19
Show Gist options
  • Select an option

  • Save snaka/2575718 to your computer and use it in GitHub Desktop.

Select an option

Save snaka/2575718 to your computer and use it in GitHub Desktop.
Jinja2でテンプレートに関数を埋め込む
Hello, {{ hoge() }} san.
#!/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