Skip to content
Myr

[svn] added new jinja unittest and added snipped contributed by Bryan McLemore.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 9bcd411 · Browse files · 3 files+45 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+45 added−0 removed

  • tests:+7 added−0 removed
  • other:+38 added−0 removed

3 files+45 added−0 removed

modified:docs/src/devrecipies.txt+28 added
71 unmodified lines
72 {{ entry.pub_date|date }}7374Also keep in mind that Jinja knows about keywords, thus you cannot have a filter75that is called `pluralize` for example.767778Using Jinja in Django79=====================8081This snippet was contributed by Bryan McLemore. It provides a `render_to_response`82function similar to the one shipped with django just that it uses Jinja for83rendering. It applies the context processors on the context and consumes a84`RequestContext`:8586.. sourcecode:: jinja8788 from django.template.context import get_standard_processors89 from django.http import HttpResponse90 from jinja import Environment, FileSystemLoader, ChoiceLoader91 from django.conf import settings9293 loaders = []94 for location in settings.TEMPLATE_DIRS:95 loaders.append(FileSystemLoader(location))96 env = Environment(loader=ChoiceLoader(loaders))9798 def render_to_response(template, context, request=None):99 template = env.get_template(template)100 if request:101 for processor in get_standard_processors():102 context.update(processor(request))103 return HttpResponse(template.render(context))
modified:docs/src/frameworks.txt+10 added
113 unmodified lines
114Because nobody implemented this specification so far it's not documented here115but in the sourcecode of the `plugin module`_. The specification itself is116explained on the pocoo trac on the `General Template Interface`_ wiki page.117118119Django120======121122Using Jinja in django is straightforward because django has a pretty low123level response interface. Just have a look at the `developer recipies`_,124there are some examples for django.125126127.. _Pylons: http://www.pylonshq.com/128.. _General Template Interface: http://trac.pocoo.org/wiki/GeneralTemplateInterface129.. _plugin module: http://trac.pocoo.org/browser/jinja/trunk/jinja/plugin.py130.. _developer recipies: devrecipies.txt
modified:tests/test_various.py+7 added
45 unmodified lines
46 tmpl = env.from_string(RAW)47 assert tmpl.render() == '{{ FOO }} and {% BAR %}'484950def test_crazy_raw():51 from jinja import Environment52 env = Environment('{', '}', '{', '}')53 tmpl = env.from_string('{raw}{broken foo}{endraw}')54 assert tmpl.render() == '{broken foo}'555657def test_cache_dict():58 from jinja.utils import CacheDict59 d = CacheDict(3)60 d["a"] = 1
26 unmodified lines