tornado_jinja2 icon indicating copy to clipboard operation
tornado_jinja2 copied to clipboard

Integrate jinja2 with tornado

Integrate Jinja2 template engine with Tornado web-framwork

Installing tonado-jinja2 from pypi:

pip install tornado-jinja2

Useage:

Import Jinja2Loader to your project

from tornado_jinja2 import Jinja2Loader

Pass the instance of Jinja2Loader to tornado.web.Application as the value of "template_loader" parameter.
You can use the particular Loader from jinja2 and configuring jinaja2 environment by your self.

import tornado.web
import jinja2

# Create a instance of Jinja2Loader
jinja2_env = jinja2.Environment(loader=jinja2.FileSystemLoader('template/path/'), autoescape=False)
jinja2_loader = Jinja2Loader(jinja2_env)

# Give it to Tornado to replace the default Loader.
settings = dict(template_loader=jinja2_loader)
application = tornado.web.Application(handler=[],
                                      **settings)

Testing

Execuse the command in the package directory

python -m test.test -v