From f60232d52b71555e48b6c799f01e512cffa7429c Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 5 Jun 2010 14:31:27 +0200 Subject: [PATCH] Updated examples to use Django cached. --HG-- branch : trunk --- examples/bench.py | 9 +++------ examples/profile.py | 5 ++++- examples/rwbench/djangoext.py | 9 ++++++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/bench.py b/examples/bench.py index 0d5a68f..ab3d4b0 100644 --- a/examples/bench.py +++ b/examples/bench.py @@ -103,7 +103,7 @@ try: except ImportError: test_django = None else: - django_template = """\ + django_template = DjangoTemplate("""\ @@ -131,16 +131,13 @@ else: \ -""" +""") def test_django(): c = DjangoContext(context) c['navigation'] = [('index.html', 'Index'), ('downloads.html', 'Downloads'), ('products.html', 'Products')] - # recompile template each rendering because that's what django - # is doing in normal situations too. Django is not thread safe - # so we can't cache it in regular apps either. - DjangoTemplate(django_template).render(c) + django_template.render(c) try: from mako.template import Template as MakoTemplate diff --git a/examples/profile.py b/examples/profile.py index a154404..70f1e0d 100644 --- a/examples/profile.py +++ b/examples/profile.py @@ -11,6 +11,9 @@ context = { } source = """\ +% macro testmacro(x) + {{ x }} +% endmacro @@ -25,7 +28,7 @@ source = """\ % for row in table % for cell in row - ${cell} + ${testmacro(cell)} % endfor % endfor diff --git a/examples/rwbench/djangoext.py b/examples/rwbench/djangoext.py index 7cc0971..9e9fa6c 100644 --- a/examples/rwbench/djangoext.py +++ b/examples/rwbench/djangoext.py @@ -2,7 +2,14 @@ from rwbench import ROOT from os.path import join from django.conf import settings -settings.configure(TEMPLATE_DIRS=(join(ROOT, 'django'),)) +settings.configure( + TEMPLATE_DIRS=(join(ROOT, 'django'),), + TEMPLATE_LOADERS=( + ('django.template.loaders.cached.Loader', ( + 'django.template.loaders.filesystem.Loader', + )), + ) +) from django.template import loader as django_loader, Context as DjangoContext, \ Node, NodeList, Variable, TokenParser from django import template as django_template_module -- 2.26.2