Also keep in mind that Jinja knows about keywords, thus you cannot have a filter
that is called `pluralize` for example.
+
+
+Using Jinja in Django
+=====================
+
+This snippet was contributed by Bryan McLemore. It provides a `render_to_response`
+function similar to the one shipped with django just that it uses Jinja for
+rendering. It applies the context processors on the context and consumes a
+`RequestContext`:
+
+.. sourcecode:: jinja
+
+ from django.template.context import get_standard_processors
+ from django.http import HttpResponse
+ from jinja import Environment, FileSystemLoader, ChoiceLoader
+ from django.conf import settings
+
+ loaders = []
+ for location in settings.TEMPLATE_DIRS:
+ loaders.append(FileSystemLoader(location))
+ env = Environment(loader=ChoiceLoader(loaders))
+
+ def render_to_response(template, context, request=None):
+ template = env.get_template(template)
+ if request:
+ for processor in get_standard_processors():
+ context.update(processor(request))
+ return HttpResponse(template.render(context))
but in the sourcecode of the `plugin module`_. The specification itself is
explained on the pocoo trac on the `General Template Interface`_ wiki page.
+
+Django
+======
+
+Using Jinja in django is straightforward because django has a pretty low
+level response interface. Just have a look at the `developer recipies`_,
+there are some examples for django.
+
+
.. _Pylons: http://www.pylonshq.com/
.. _General Template Interface: http://trac.pocoo.org/wiki/GeneralTemplateInterface
.. _plugin module: http://trac.pocoo.org/browser/jinja/trunk/jinja/plugin.py
+.. _developer recipies: devrecipies.txt
assert tmpl.render() == '{{ FOO }} and {% BAR %}'
+def test_crazy_raw():
+ from jinja import Environment
+ env = Environment('{', '}', '{', '}')
+ tmpl = env.from_string('{raw}{broken foo}{endraw}')
+ assert tmpl.render() == '{broken foo}'
+
+
def test_cache_dict():
from jinja.utils import CacheDict
d = CacheDict(3)