Frequently Asked Questions
Here a list of frequently asked questions.
Why the Name?
The name Jinja was chosen because it's the name of a Japanese temple and temple and template share a similar pronunciation.
How fast is it?
I really hate benchmarks especially since they don't reflect much. The performance of a template depends on many factors and you would have to benchmark different engines in differen situations. However Jinja isn't slow. The benchmarks from the testsuite show that Jinja is about twice as fast as Django templates and about three times as slow as mako. That's not bad for a sandboxed template engine that has to sanitize template input on the fly. If you really need the best performance of a template engine consider using mako.
What happened to Jinja < 1?
Before Jinja 1 there was a template engine too with the same name. Beside the name and the same maintainer those two projects don't share a single line of code. If you have an application using Jinja < 1 you should try to make it Jinja 1 compatible. If that's not possible, the old project is still available as 0.9-maint in the old Jinja subversion repository.
Why should I use Jinja?
There are dozens of template engines for Python, many of them try to achieve different things. If you are looking for a XML based template engine have a look at genshi, if you want a bleezing fast template engine with the full range of python constructs have a look at mako. If you want sandboxed templates you probably want to check out Jinja.
Differences to Django
While the Jinja default syntax looks pretty much like Django the rest of the template engine works completely different. Jinja was designed to be used without Django and to support Python expressions.
Features that Jinja has in common with Django
- filter functions
- block based template inheritance
- the {% cycle %} and {% filter %} tag
- being sandboxed
- similar default syntax
Differences to Django
- advanced lexer that allows escaping of tags
- generation of bytecode for faster template execution
- definition of macros (often recurring tasks like rendering dialog boxes, form elements etc.)
- raw blocks
- uncoupled internationalization support
- expression support in any tag
- abbility of modifying the context from the template by using the {% set %} tag.
- support for function calling with arguments
- filters can be called with a variable argument count
- full unicode support
- deferred objects (objects that are resolved on first access, not on context instanciation)
- Support for recursing by using recursing for loops or self calling macros.
- If blocks have support for multiple elif statements
- for loops have an optional else block executed if there was no iteration.
- test functions like is even etc.
- block delimiters are exchangeable.
- no implicit function calling
- {% endblock %} doesn't support the optional name argument
- {% ifchanged %} is not implemented because of performance reasons. If there's enough interest an implementation might be added
- {% templatetag %} is not implemented because Jinja supports escaping via {% raw %} or the variable syntax
- {% comment %} is not implemented. Use {# ... #} for commenting out stuff.
- {% now %} is not implemented because Jinja doesn't handle l10n. Datetime specific stuff should be provided by the application.
- {% load %}, loading components for Jinja works from the application side. Template designers don't have to import stuff on their own.
- {% debug %} is not implemented. You can use the global function debug().
- custom tags are not supported. Most of the stuff that is possible with django template tags is possible with either functions, filters, tests or a combination of them.
- using keywords like endfor as identifer raises an exception.