Skip to main content

jinja2 template support for tornado web framework

Project description

License: MIT License

jinja2 support for tornado applications.

Install

$ python setup.py install

Usage

from jinja_tornado import JinjaApp, JinjaTemplateMixin

application = tornado.web.Application( ... )

environment = JinjaApp.init_app(application)
"""init_app returns jinja2 environment that is used by application.
takes a dict as second argument which contains your custom jinja 2
settings for environment constructor.
see http://jinja.pocoo.org/docs/api/#jinja2.Environment """



class JinjaEnabledHandler(JinjaTemplateMixin, tornado.web.RequestHandler):
    """ this Handler supports
        - `self.session` properties (as flask.session) and `session` in template
        - `self.render` method
        - `self.render_string` method """




# custom filters, tests, globals
environment = JinjaApp.init_app(application)
@environment.filter()
def foo_to_bar(x):
    return x.replace('foo', 'bar')

Template variables

request        => tornado.web.RequestHandler.request
session        => tornado.web.RequestHandler.get_secure_cookie('session')
path_args      => tornado.web.RequestHandler.path_args
path_kwargs    => tornado.web.RequestHandler.path_kwargs
settings       => tornado.web.RequestHandler.application.settings
reverse_url    => tornado.web.RequestHandler.application.reverse_url
static_url     => tornado.web.RequestHandler.static_url
xsrf_form_html => tornado.web.RequestHandler.xsrf_form_html
datetime       => datetime (python module)
locale         => tornado.web.RequestHandler.locale
_              => tornado.web.RequestHandler.locale.translate
handler        => tornado.web.RequestHandler (self)
current_user   => tornado.web.requestHandler.current_user

Template filters

tojson       => JSON-encode the given python object

    <script>
      var obj = {{ obj | tojson | safe }}
    </script>

xhtml_escape => tornado.escape.xhtml_escape
url_escape   => tornado.escape.url_escape
squeeze      => tornado.escape.squeeze
linkify      => tornado.escape.linkify

Todo

  • write tests

  • no more opinionated session implementation

  • implement template preprocessors

  • UIModules, and various ‘tornado’ template structures

Authors

License

MIT License. See: LICENSE

History

release/v0.1.0 (2016-04-28 17:13:31 -0500)

git log --reverse --pretty=format:'* %s [%h]' b8d13ce..release/v0.1.0
  • initial commit [2defc31]

  • 2nd commit [c05ab84]

  • now it is a package [0993866]

  • fixed __init__ and readme [2f1171e]

  • Update README.md [f78735d]

  • Update jinja_tornado.py [6df0211]

  • Update README.md [01fa568]

  • REF: README.md -> README.rst [49927dd]

  • BLD,DOC: Makefile, README.rst, requirements.txt, setup.py: v0.1.0 packaging [d96bdf3]

  • DOC,BLD: HISTORY.rst, setup.py: add HISTORY.rst to long_description [4fbcb84]

  • DOC: README.rst: Authors [3f8dd1a]

  • DOC: setup.py: author, author_email, url [10e837a]

  • DOC: LICENSE: amend (MIT) LICENSE copyright [0e6641a]

  • BLD: MANIFEST.in: add MANIFEST.in [746358b]

  • BLD: Makefile: ‘python setup.py check -r -s’ [d196959]

  • DOC: HISTORY.rst: git-changelog.py -r release/v0.1.0 –hdr=- | pbcopy [824a131]

  • BLD: Makefile, requirements[-dev].txt: development requirements [54113b5]

  • BLD: Makefile: twine register because HTTPS [c4d1535]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jinja_tornado-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jinja_tornado-0.1.0-py2-none-any.whl (7.0 kB view details)

Uploaded Python 2

File details

Details for the file jinja_tornado-0.1.0.tar.gz.

File metadata

  • Download URL: jinja_tornado-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jinja_tornado-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b746fc4b76c9851d2c40d4674fcee08d9aacfb6f8fdc740482b331b90d6bfdda
MD5 2cd47637019b8b080ceeb6342421f9f3
BLAKE2b-256 2005f81372e9563dec80163a8fb2c9e2b142de9df95191ffcbe809ca544b57a3

See more details on using hashes here.

File details

Details for the file jinja_tornado-0.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for jinja_tornado-0.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 e4543b9ef546a51c37a60828fc8424faea2c6f7447d5e8c8a08fac495dec9c53
MD5 93dca7de8aa72c49d1e25cb81dec9a56
BLAKE2b-256 ca1075f32c8fb538a90b008090c2010c4b525edbb1bda1fcd1feac16ee8e79a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page