Jinja2 is a template engine written in pure Python. It provides a Django inspired non-XML syntax but supports inline expressions and an optional sandboxed environment.


Here a small example of a Jinja2 template:

{% extends 'base.html' %}
{% block title %}Memberlist{% endblock %}
{% block content %}
  {% for user in users %}
    <li><a href="{{ user.url }}">{{ user.username }}</a></li>
  {% endfor %}
{% endblock %}
  1. 2010 by the Jinja Team.

BSD, see LICENSE for more details.


clear_caches() Jinja2 keeps internal caches for environments and lexers.
contextfilter(f) Decorator for marking context dependent filters.
contextfunction(f) This decorator can be used to mark a function or method context callable.
environmentfilter(f) Decorator for marking evironment dependent filters.
environmentfunction(f) This decorator can be used to mark a function or method as environment callable.
escape((s) -> markup) Convert the characters &, <, >, ‘, and ” in string s to HTML-safe sequences.
evalcontextfilter(f) Decorator for marking eval-context dependent filters.
evalcontextfunction(f) This decorator can be used to mark a function or method as an eval context callable.
is_undefined(obj) Check if the object passed is undefined.
make_logging_undefined([logger, base]) Given a logger object this returns a new undefined class that will log certain failures.


BaseLoader Baseclass for all loaders.
BytecodeCache To implement your own bytecode cache you have to subclass this class and override load_bytecode() and dump_bytecode().
ChoiceLoader(loaders) This loader works like the PrefixLoader just that no prefix is specified.
DebugUndefined([hint, obj, name, exc]) An undefined that returns the debug info when printed.
DictLoader(mapping) Loads a template from a python dict.
Environment([block_start_string, ...]) The core component of Jinja is the Environment.
FileSystemBytecodeCache([directory, pattern]) A bytecode cache that stores bytecode on the filesystem.
FileSystemLoader(searchpath[, encoding, ...]) Loads templates from the file system.
FunctionLoader(load_func) A loader that is passed a function which does the loading.
Markup Marks a string as being safe for inclusion in HTML/XML output without needing to be escaped.
MemcachedBytecodeCache(client[, prefix, ...]) This class implements a bytecode cache that uses a memcache cache for storing the information.
ModuleLoader(path) This loader loads templates from precompiled templates.
PackageLoader(package_name[, package_path, ...]) Load templates from python eggs or packages.
PrefixLoader(mapping[, delimiter]) A loader that is passed a dict of loaders where each loader is bound to a prefix.
StrictUndefined([hint, obj, name, exc]) An undefined that barks on print and iteration as well as boolean tests and all kinds of comparisons.
Template The central template object.
Undefined([hint, obj, name, exc]) The default undefined type.


TemplateAssertionError(message, lineno[, ...]) Like a template syntax error, but covers cases where something in the template caused an error at compile time that wasn’t necessarily caused by a syntax error.
TemplateError([message]) Baseclass for all template errors.
TemplateNotFound(name[, message]) Raised if a template does not exist.
TemplateSyntaxError(message, lineno[, name, ...]) Raised to tell the user that there is a problem with the template.
TemplatesNotFound([names, message]) Like TemplateNotFound but raised if multiple templates are selected.
UndefinedError([message]) Raised if a template tries to operate on Undefined.