Skip to main content

A small but fast and easy to use stand-alone template engine written in pure python.

Project description

Jinja is a small but very fast and easy to use stand-alone template engine written in pure Python.

Since version 0.6 it uses a new parser that increases parsing performance a lot by caching the nodelists on disk if wanted.

It includes multiple template inheritance and other features like simple value escaping.

Template Syntax

This is a small example template in which you can see how Jinja’s syntax looks like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>My Webpage</title>
</head
<body>
    <ul id="navigation">
    {% for item in navigation %}
        <li><a href="{{ item.href }}">{{ item.caption|e }}</a></li>
    {% endfor %}
    </ul>

    <h1>My Webpage</h1>
    {{ variable }}
</body>
</html>

Usage

Here is a small example:

from jinja import Template, Context, FileSystemLoader

t = Template('mytemplate', FileSystemLoader('/path/to/the/templates'))
c = Context({
    'navigation' [
        {'href': '#', 'caption': 'Index'},
        {'href': '#', 'caption': 'Spam'}
    ],
    'variable': '<strong>hello world</strong>'
})
print t.render(c)

Unicode Support

Jinja comes with built-in Unicode support. As a matter of fact, the return value of Template.render() will be a Python unicode object.

You can still output str objects as well when you encode the result:

s = t.render(c).encode('utf-8')

For more examples check out the documentation on the jinja webpage.

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-0.9.tar.gz (55.8 kB view details)

Uploaded Source

Built Distributions

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

Jinja-0.9-py2.4.egg (73.6 kB view details)

Uploaded Egg

Jinja-0.9-py2.3.egg (266.3 kB view details)

Uploaded Egg

File details

Details for the file Jinja-0.9.tar.gz.

File metadata

  • Download URL: Jinja-0.9.tar.gz
  • Upload date:
  • Size: 55.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Jinja-0.9.tar.gz
Algorithm Hash digest
SHA256 652db44e332b65fdd797665a52e9f7527e437d2b943bbc010bee88cd38d76bbe
MD5 a5aaebb6285e044b6b9d56facae1c1f2
BLAKE2b-256 a8199d84d6ca5e5ddde977d47fac105d5eee909d2cf0503c13348cccd0ea0b1b

See more details on using hashes here.

File details

Details for the file Jinja-0.9-py2.4.egg.

File metadata

  • Download URL: Jinja-0.9-py2.4.egg
  • Upload date:
  • Size: 73.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Jinja-0.9-py2.4.egg
Algorithm Hash digest
SHA256 6f5dd0bae943d11d4eede88a837892f11638d8d8cc1b9f3053c3f21d9a72823d
MD5 96a179ef2539a4fb42bd207c2d7e4bc2
BLAKE2b-256 de06915a78def7246609211eaa554b063f95d76cc92813a9d24832b529e2200b

See more details on using hashes here.

File details

Details for the file Jinja-0.9-py2.3.egg.

File metadata

  • Download URL: Jinja-0.9-py2.3.egg
  • Upload date:
  • Size: 266.3 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Jinja-0.9-py2.3.egg
Algorithm Hash digest
SHA256 762583b880d034df57fe7fe712ec38b27bbc9b25f62485495674a4edca136e61
MD5 5792a0cd8ebcf430b841486b03429a0f
BLAKE2b-256 1c7308ce22ca6c8679d023216e8da746ba60831b262f085d07b00727aa74b6a0

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