Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6262 -- Added a cached template loader, and modified existing …

…template loaders and tag to be cacheable. Thanks to Mike Malone for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11862 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 44b9076bbed3e629230d9b77a8765e4c906036d1 1 parent 5a23505
Russell Keith-Magee authored December 14, 2009
1  AUTHORS
@@ -288,6 +288,7 @@ answer newbie questions, and generally made Django that much better:
288 288
     Martin Mahner <http://www.mahner.org/>
289 289
     Matt McClanahan <http://mmcc.cx/>
290 290
     Frantisek Malina <vizualbod@vizualbod.com>
  291
+    Mike Malone <mjmalone@gmail.com>
291 292
     Martin Maney <http://www.chipy.org/Martin_Maney>
292 293
     masonsimon+django@gmail.com
293 294
     Manuzhai
6  django/conf/global_settings.py
@@ -158,9 +158,9 @@
158 158
 # See the comments in django/core/template/loader.py for interface
159 159
 # documentation.
160 160
 TEMPLATE_LOADERS = (
161  
-    'django.template.loaders.filesystem.load_template_source',
162  
-    'django.template.loaders.app_directories.load_template_source',
163  
-#     'django.template.loaders.eggs.load_template_source',
  161
+    'django.template.loaders.filesystem.Loader',
  162
+    'django.template.loaders.app_directories.Loader',
  163
+#     'django.template.loaders.eggs.Loader',
164 164
 )
165 165
 
166 166
 # List of processors used by RequestContext to populate the context.
6  django/conf/project_template/settings.py
@@ -52,9 +52,9 @@
52 52
 
53 53
 # List of callables that know how to import templates from various sources.
54 54
 TEMPLATE_LOADERS = (
55  
-    'django.template.loaders.filesystem.load_template_source',
56  
-    'django.template.loaders.app_directories.load_template_source',
57  
-#     'django.template.loaders.eggs.load_template_source',
  55
+    'django.template.loaders.filesystem.Loader',
  56
+    'django.template.loaders.app_directories.Loader',
  57
+#     'django.template.loaders.eggs.Loader',
58 58
 )
59 59
 
60 60
 MIDDLEWARE_CLASSES = (
9  django/template/__init__.py
@@ -173,9 +173,16 @@ def __iter__(self):
173 173
             for subnode in node:
174 174
                 yield subnode
175 175
 
  176
+    def _render(self, context):
  177
+        return self.nodelist.render(context)
  178
+
176 179
     def render(self, context):
177 180
         "Display stage -- can be called many times"
178  
-        return self.nodelist.render(context)
  181
+        context.render_context.push()
  182
+        try:
  183
+            return self._render(context)
  184
+        finally:
  185
+            context.render_context.pop()
179 186
 
180 187
 def compile_string(template_string, origin):
181 188
     "Compiles template_string into NodeList ready for rendering"
62  django/template/context.py
@@ -12,45 +12,42 @@ class ContextPopException(Exception):
12 12
     "pop() has been called more times than push()"
13 13
     pass
14 14
 
15  
-class Context(object):
16  
-    "A stack container for variable context"
17  
-    def __init__(self, dict_=None, autoescape=True, current_app=None):
  15
+class BaseContext(object):
  16
+    def __init__(self, dict_=None):
18 17
         dict_ = dict_ or {}
19 18
         self.dicts = [dict_]
20  
-        self.autoescape = autoescape
21  
-        self.current_app = current_app
22 19
 
23 20
     def __repr__(self):
24 21
         return repr(self.dicts)
25 22
 
26 23
     def __iter__(self):
27  
-        for d in self.dicts:
  24
+        for d in reversed(self.dicts):
28 25
             yield d
29 26
 
30 27
     def push(self):
31 28
         d = {}
32  
-        self.dicts = [d] + self.dicts
  29
+        self.dicts.append(d)
33 30
         return d
34 31
 
35 32
     def pop(self):
36 33
         if len(self.dicts) == 1:
37 34
             raise ContextPopException
38  
-        return self.dicts.pop(0)
  35
+        return self.dicts.pop()
39 36
 
40 37
     def __setitem__(self, key, value):
41 38
         "Set a variable in the current context"
42  
-        self.dicts[0][key] = value
  39
+        self.dicts[-1][key] = value
43 40
 
44 41
     def __getitem__(self, key):
45 42
         "Get a variable's value, starting at the current context and going upward"
46  
-        for d in self.dicts:
  43
+        for d in reversed(self.dicts):
47 44
             if key in d:
48 45
                 return d[key]
49 46
         raise KeyError(key)
50 47
 
51 48
     def __delitem__(self, key):
52 49
         "Delete a variable from the current context"
53  
-        del self.dicts[0][key]
  50
+        del self.dicts[-1][key]
54 51
 
55 52
     def has_key(self, key):
56 53
         for d in self.dicts:
@@ -58,21 +55,58 @@ def has_key(self, key):
58 55
                 return True
59 56
         return False
60 57
 
61  
-    __contains__ = has_key
  58
+    def __contains__(self, key):
  59
+        return self.has_key(key)
62 60
 
63 61
     def get(self, key, otherwise=None):
64  
-        for d in self.dicts:
  62
+        for d in reversed(self.dicts):
65 63
             if key in d:
66 64
                 return d[key]
67 65
         return otherwise
68 66
 
  67
+class Context(BaseContext):
  68
+    "A stack container for variable context"
  69
+    def __init__(self, dict_=None, autoescape=True, current_app=None):
  70
+        self.autoescape = autoescape
  71
+        self.current_app = current_app
  72
+        self.render_context = RenderContext()
  73
+        super(Context, self).__init__(dict_)
  74
+
69 75
     def update(self, other_dict):
70 76
         "Like dict.update(). Pushes an entire dictionary's keys and values onto the context."
71 77
         if not hasattr(other_dict, '__getitem__'):
72 78
             raise TypeError('other_dict must be a mapping (dictionary-like) object.')
73  
-        self.dicts = [other_dict] + self.dicts
  79
+        self.dicts.append(other_dict)
74 80
         return other_dict
75 81
 
  82
+class RenderContext(BaseContext):
  83
+    """
  84
+    A stack container for storing Template state.
  85
+
  86
+    RenderContext simplifies the implementation of template Nodes by providing a
  87
+    safe place to store state between invocations of a node's `render` method.
  88
+
  89
+    The RenderContext also provides scoping rules that are more sensible for
  90
+    'template local' variables. The render context stack is pushed before each
  91
+    template is rendered, creating a fresh scope with nothing in it. Name
  92
+    resolution fails if a variable is not found at the top of the RequestContext
  93
+    stack. Thus, variables are local to a specific template and don't affect the
  94
+    rendering of other templates as they would if they were stored in the normal
  95
+    template context.
  96
+    """
  97
+    def __iter__(self):
  98
+        for d in self.dicts[-1]:
  99
+            yield d
  100
+
  101
+    def has_key(self, key):
  102
+        return key in self.dicts[-1]
  103
+
  104
+    def get(self, key, otherwise=None):
  105
+        d = self.dicts[-1]
  106
+        if key in d:
  107
+            return d[key]
  108
+        return otherwise
  109
+
76 110
 # This is a function rather than module-level procedural code because we only
77 111
 # want it to execute if somebody uses RequestContext.
78 112
 def get_standard_processors():
7  django/template/defaulttags.py
@@ -57,11 +57,14 @@ def render(self, context):
57 57
 
58 58
 class CycleNode(Node):
59 59
     def __init__(self, cyclevars, variable_name=None):
60  
-        self.cycle_iter = itertools_cycle(cyclevars)
  60
+        self.cyclevars = cyclevars
61 61
         self.variable_name = variable_name
62 62
 
63 63
     def render(self, context):
64  
-        value = self.cycle_iter.next().resolve(context)
  64
+        if self not in context.render_context:
  65
+            context.render_context[self] = itertools_cycle(self.cyclevars)
  66
+        cycle_iter = context.render_context[self]
  67
+        value = cycle_iter.next().resolve(context)
65 68
         if self.variable_name:
66 69
             context[self.variable_name] = value
67 70
         return value
103  django/template/loader.py
@@ -27,6 +27,36 @@
27 27
 
28 28
 template_source_loaders = None
29 29
 
  30
+class BaseLoader(object):
  31
+    is_usable = False
  32
+
  33
+    def __init__(self, *args, **kwargs):
  34
+        pass
  35
+
  36
+    def __call__(self, template_name, template_dirs=None):
  37
+        return self.load_template(template_name, template_dirs)
  38
+
  39
+    def load_template(self, template_name, template_dirs=None):
  40
+        source, origin = self.load_template_source(template_name, template_dirs)
  41
+        template = get_template_from_string(source, name=template_name)
  42
+        return template, origin
  43
+
  44
+    def load_template_source(self, template_name, template_dirs=None):
  45
+        """
  46
+        Returns a tuple containing the source and origin for the given template
  47
+        name.
  48
+
  49
+        """
  50
+        raise NotImplementedError
  51
+
  52
+    def reset(self):
  53
+        """
  54
+        Resets any state maintained by the loader instance (e.g., cached
  55
+        templates or cached loader modules).
  56
+
  57
+        """
  58
+        pass
  59
+
30 60
 class LoaderOrigin(Origin):
31 61
     def __init__(self, display_name, loader, name, dirs):
32 62
         super(LoaderOrigin, self).__init__(display_name)
@@ -41,29 +71,50 @@ def make_origin(display_name, loader, name, dirs):
41 71
     else:
42 72
         return None
43 73
 
44  
-def find_template_source(name, dirs=None):
  74
+def find_template_loader(loader):
  75
+    if hasattr(loader, '__iter__'):
  76
+        loader, args = loader[0], loader[1:]
  77
+    else:
  78
+        args = []
  79
+    if isinstance(loader, basestring):
  80
+        module, attr = loader.rsplit('.', 1)
  81
+        try:
  82
+            mod = import_module(module)
  83
+        except ImportError:
  84
+            raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e))
  85
+        try:
  86
+            TemplateLoader = getattr(mod, attr)
  87
+        except AttributeError, e:
  88
+            raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e))
  89
+
  90
+        if hasattr(TemplateLoader, 'load_template_source'):
  91
+            func = TemplateLoader(*args)
  92
+        else:
  93
+            # Try loading module the old way - string is full path to callable
  94
+            if args:
  95
+                raise ImproperlyConfigured("Error importing template source loader %s - can't pass arguments to function-based loader." % loader)
  96
+            func = TemplateLoader
  97
+
  98
+        if not func.is_usable:
  99
+            import warnings
  100
+            warnings.warn("Your TEMPLATE_LOADERS setting includes %r, but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS." % loader)
  101
+            return None
  102
+        else:
  103
+            return func
  104
+    else:
  105
+        raise ImproperlyConfigured('Loader does not define a "load_template" callable template source loader')
  106
+
  107
+def find_template(name, dirs=None):
45 108
     # Calculate template_source_loaders the first time the function is executed
46 109
     # because putting this logic in the module-level namespace may cause
47 110
     # circular import errors. See Django ticket #1292.
48 111
     global template_source_loaders
49 112
     if template_source_loaders is None:
50 113
         loaders = []
51  
-        for path in settings.TEMPLATE_LOADERS:
52  
-            i = path.rfind('.')
53  
-            module, attr = path[:i], path[i+1:]
54  
-            try:
55  
-                mod = import_module(module)
56  
-            except ImportError, e:
57  
-                raise ImproperlyConfigured, 'Error importing template source loader %s: "%s"' % (module, e)
58  
-            try:
59  
-                func = getattr(mod, attr)
60  
-            except AttributeError:
61  
-                raise ImproperlyConfigured, 'Module "%s" does not define a "%s" callable template source loader' % (module, attr)
62  
-            if not func.is_usable:
63  
-                import warnings
64  
-                warnings.warn("Your TEMPLATE_LOADERS setting includes %r, but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS." % path)
65  
-            else:
66  
-                loaders.append(func)
  114
+        for loader_name in settings.TEMPLATE_LOADERS:
  115
+            loader = find_template_loader(loader_name)
  116
+            if loader is not None:
  117
+                loaders.append(loader)
67 118
         template_source_loaders = tuple(loaders)
68 119
     for loader in template_source_loaders:
69 120
         try:
@@ -73,13 +124,27 @@ def find_template_source(name, dirs=None):
73 124
             pass
74 125
     raise TemplateDoesNotExist, name
75 126
 
  127
+def find_template_source(name, dirs=None):
  128
+    # For backward compatibility
  129
+    import warnings
  130
+    warnings.warn(
  131
+        "`django.template.loaders.find_template_source` is deprecated; use `django.template.loaders.find_template` instead.",
  132
+        PendingDeprecationWarning
  133
+    )
  134
+    template, origin = find_template(name, dirs)
  135
+    if hasattr(template, 'render'):
  136
+        raise Exception("Found a compiled template that is incompatible with the deprecated `django.template.loaders.find_template_source` function.")
  137
+    return template, origin
  138
+
76 139
 def get_template(template_name):
77 140
     """
78 141
     Returns a compiled Template object for the given template name,
79 142
     handling template inheritance recursively.
80 143
     """
81  
-    source, origin = find_template_source(template_name)
82  
-    template = get_template_from_string(source, origin, template_name)
  144
+    template, origin = find_template(template_name)
  145
+    if not hasattr(template, 'render'):
  146
+        # template needs to be compiled
  147
+        template = get_template_from_string(template, origin, template_name)
83 148
     return template
84 149
 
85 150
 def get_template_from_string(source, origin=None, name=None):
115  django/template/loader_tags.py
... ...
@@ -1,14 +1,43 @@
1 1
 from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable
2 2
 from django.template import Library, Node, TextNode
3  
-from django.template.loader import get_template, get_template_from_string, find_template_source
  3
+from django.template.loader import get_template
4 4
 from django.conf import settings
5 5
 from django.utils.safestring import mark_safe
6 6
 
7 7
 register = Library()
8 8
 
  9
+BLOCK_CONTEXT_KEY = 'block_context'
  10
+
9 11
 class ExtendsError(Exception):
10 12
     pass
11 13
 
  14
+class BlockContext(object):
  15
+    def __init__(self):
  16
+        # Dictionary of FIFO queues.
  17
+        self.blocks = {}
  18
+
  19
+    def add_blocks(self, blocks):
  20
+        for name, block in blocks.iteritems():
  21
+            if name in self.blocks:
  22
+                self.blocks[name].insert(0, block)
  23
+            else:
  24
+                self.blocks[name] = [block]
  25
+
  26
+    def pop(self, name):
  27
+        try:
  28
+            return self.blocks[name].pop()
  29
+        except (IndexError, KeyError):
  30
+            return None
  31
+
  32
+    def push(self, name, block):
  33
+        self.blocks[name].append(block)
  34
+
  35
+    def get_block(self, name):
  36
+        try:
  37
+            return self.blocks[name][-1]
  38
+        except (IndexError, KeyError):
  39
+            return None
  40
+
12 41
 class BlockNode(Node):
13 42
     def __init__(self, name, nodelist, parent=None):
14 43
         self.name, self.nodelist, self.parent = name, nodelist, parent
@@ -17,25 +46,32 @@ def __repr__(self):
17 46
         return "<Block Node: %s. Contents: %r>" % (self.name, self.nodelist)
18 47
 
19 48
     def render(self, context):
  49
+        block_context = context.render_context.get(BLOCK_CONTEXT_KEY)
20 50
         context.push()
21  
-        # Save context in case of block.super().
22  
-        self.context = context
23  
-        context['block'] = self
24  
-        result = self.nodelist.render(context)
  51
+        if block_context is None:
  52
+            context['block'] = self
  53
+            result = self.nodelist.render(context)
  54
+        else:
  55
+            push = block = block_context.pop(self.name)
  56
+            if block is None:
  57
+                block = self
  58
+            # Create new block so we can store context without thread-safety issues.
  59
+            block = BlockNode(block.name, block.nodelist)
  60
+            block.context = context
  61
+            context['block'] = block
  62
+            result = block.nodelist.render(context)
  63
+            if push is not None:
  64
+                block_context.push(self.name, push)
25 65
         context.pop()
26 66
         return result
27 67
 
28 68
     def super(self):
29  
-        if self.parent:
30  
-            return mark_safe(self.parent.render(self.context))
  69
+        render_context = self.context.render_context
  70
+        if (BLOCK_CONTEXT_KEY in render_context and
  71
+            render_context[BLOCK_CONTEXT_KEY].get_block(self.name) is not None):
  72
+            return mark_safe(self.render(self.context))
31 73
         return ''
32 74
 
33  
-    def add_parent(self, nodelist):
34  
-        if self.parent:
35  
-            self.parent.add_parent(nodelist)
36  
-        else:
37  
-            self.parent = BlockNode(self.name, nodelist)
38  
-
39 75
 class ExtendsNode(Node):
40 76
     must_be_first = True
41 77
 
@@ -43,6 +79,7 @@ def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
43 79
         self.nodelist = nodelist
44 80
         self.parent_name, self.parent_name_expr = parent_name, parent_name_expr
45 81
         self.template_dirs = template_dirs
  82
+        self.blocks = dict([(n.name, n) for n in nodelist.get_nodes_by_type(BlockNode)])
46 83
 
47 84
     def __repr__(self):
48 85
         if self.parent_name_expr:
@@ -61,40 +98,34 @@ def get_parent(self, context):
61 98
         if hasattr(parent, 'render'):
62 99
             return parent # parent is a Template object
63 100
         try:
64  
-            source, origin = find_template_source(parent, self.template_dirs)
  101
+            return get_template(parent)
65 102
         except TemplateDoesNotExist:
66 103
             raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
67  
-        else:
68  
-            return get_template_from_string(source, origin, parent)
69 104
 
70 105
     def render(self, context):
71 106
         compiled_parent = self.get_parent(context)
72  
-        parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)])
73  
-        for block_node in self.nodelist.get_nodes_by_type(BlockNode):
74  
-            # Check for a BlockNode with this node's name, and replace it if found.
75  
-            try:
76  
-                parent_block = parent_blocks[block_node.name]
77  
-            except KeyError:
78  
-                # This BlockNode wasn't found in the parent template, but the
79  
-                # parent block might be defined in the parent's *parent*, so we
80  
-                # add this BlockNode to the parent's ExtendsNode nodelist, so
81  
-                # it'll be checked when the parent node's render() is called.
82  
-
83  
-                # Find out if the parent template has a parent itself
84  
-                for node in compiled_parent.nodelist:
85  
-                    if not isinstance(node, TextNode):
86  
-                        # If the first non-text node is an extends, handle it.
87  
-                        if isinstance(node, ExtendsNode):
88  
-                            node.nodelist.append(block_node)
89  
-                        # Extends must be the first non-text node, so once you find
90  
-                        # the first non-text node you can stop looking. 
91  
-                        break
92  
-            else:
93  
-                # Keep any existing parents and add a new one. Used by BlockNode.
94  
-                parent_block.parent = block_node.parent
95  
-                parent_block.add_parent(parent_block.nodelist)
96  
-                parent_block.nodelist = block_node.nodelist
97  
-        return compiled_parent.render(context)
  107
+
  108
+        if BLOCK_CONTEXT_KEY not in context.render_context:
  109
+            context.render_context[BLOCK_CONTEXT_KEY] = BlockContext()
  110
+        block_context = context.render_context[BLOCK_CONTEXT_KEY]
  111
+
  112
+        # Add the block nodes from this node to the block context
  113
+        block_context.add_blocks(self.blocks)
  114
+
  115
+        # If this block's parent doesn't have an extends node it is the root,
  116
+        # and its block nodes also need to be added to the block context.
  117
+        for node in compiled_parent.nodelist:
  118
+            # The ExtendsNode has to be the first non-text node.
  119
+            if not isinstance(node, TextNode):
  120
+                if not isinstance(node, ExtendsNode):
  121
+                    blocks = dict([(n.name, n) for n in
  122
+                                   compiled_parent.nodelist.get_nodes_by_type(BlockNode)])
  123
+                    block_context.add_blocks(blocks)
  124
+                break
  125
+
  126
+        # Call Template._render explicitly so the parser context stays
  127
+        # the same.
  128
+        return compiled_parent._render(context)
98 129
 
99 130
 class ConstantIncludeNode(Node):
100 131
     def __init__(self, template_path):
65  django/template/loaders/app_directories.py
@@ -9,6 +9,7 @@
9 9
 from django.conf import settings
10 10
 from django.core.exceptions import ImproperlyConfigured
11 11
 from django.template import TemplateDoesNotExist
  12
+from django.template.loader import BaseLoader
12 13
 from django.utils._os import safe_join
13 14
 from django.utils.importlib import import_module
14 15
 
@@ -27,29 +28,47 @@
27 28
 # It won't change, so convert it to a tuple to save memory.
28 29
 app_template_dirs = tuple(app_template_dirs)
29 30
 
30  
-def get_template_sources(template_name, template_dirs=None):
31  
-    """
32  
-    Returns the absolute paths to "template_name", when appended to each
33  
-    directory in "template_dirs". Any paths that don't lie inside one of the
34  
-    template dirs are excluded from the result set, for security reasons.
35  
-    """
36  
-    if not template_dirs:
37  
-        template_dirs = app_template_dirs
38  
-    for template_dir in template_dirs:
39  
-        try:
40  
-            yield safe_join(template_dir, template_name)
41  
-        except UnicodeDecodeError:
42  
-            # The template dir name was a bytestring that wasn't valid UTF-8.
43  
-            raise
44  
-        except ValueError:
45  
-            # The joined path was located outside of template_dir.
46  
-            pass
  31
+class Loader(BaseLoader):
  32
+    is_usable = True
  33
+
  34
+    def get_template_sources(self, template_name, template_dirs=None):
  35
+        """
  36
+        Returns the absolute paths to "template_name", when appended to each
  37
+        directory in "template_dirs". Any paths that don't lie inside one of the
  38
+        template dirs are excluded from the result set, for security reasons.
  39
+        """
  40
+        if not template_dirs:
  41
+            template_dirs = app_template_dirs
  42
+        for template_dir in template_dirs:
  43
+            try:
  44
+                yield safe_join(template_dir, template_name)
  45
+            except UnicodeDecodeError:
  46
+                # The template dir name was a bytestring that wasn't valid UTF-8.
  47
+                raise
  48
+            except ValueError:
  49
+                # The joined path was located outside of template_dir.
  50
+                pass
  51
+
  52
+    def load_template_source(self, template_name, template_dirs=None):
  53
+        for filepath in self.get_template_sources(template_name, template_dirs):
  54
+            try:
  55
+                file = open(filepath)
  56
+                try:
  57
+                    return (file.read().decode(settings.FILE_CHARSET), filepath)
  58
+                finally:
  59
+                    file.close()
  60
+            except IOError:
  61
+                pass
  62
+        raise TemplateDoesNotExist, template_name
  63
+
  64
+_loader = Loader()
47 65
 
48 66
 def load_template_source(template_name, template_dirs=None):
49  
-    for filepath in get_template_sources(template_name, template_dirs):
50  
-        try:
51  
-            return (open(filepath).read().decode(settings.FILE_CHARSET), filepath)
52  
-        except IOError:
53  
-            pass
54  
-    raise TemplateDoesNotExist, template_name
  67
+    # For backwards compatibility
  68
+    import warnings
  69
+    warnings.warn(
  70
+        "'django.template.loaders.app_directories.load_template_source' is deprecated; use 'django.template.loaders.app_directories.Loader' instead.",
  71
+        PendingDeprecationWarning
  72
+    )
  73
+    return _loader.load_template_source(template_name, template_dirs)
55 74
 load_template_source.is_usable = True
46  django/template/loaders/cached.py
... ...
@@ -0,0 +1,46 @@
  1
+"""
  2
+Wrapper class that takes a list of template loaders as an argument and attempts
  3
+to load templates from them in order, caching the result.
  4
+"""
  5
+
  6
+from django.template import TemplateDoesNotExist
  7
+from django.template.loader import BaseLoader, get_template_from_string, find_template_loader, make_origin
  8
+from django.utils.importlib import import_module
  9
+from django.core.exceptions import ImproperlyConfigured
  10
+
  11
+class Loader(BaseLoader):
  12
+    is_usable = True
  13
+
  14
+    def __init__(self, loaders):
  15
+        self.template_cache = {}
  16
+        self._loaders = loaders
  17
+        self._cached_loaders = []
  18
+
  19
+    @property
  20
+    def loaders(self):
  21
+        # Resolve loaders on demand to avoid circular imports
  22
+        if not self._cached_loaders:
  23
+            for loader in self._loaders:
  24
+                self._cached_loaders.append(find_template_loader(loader))
  25
+        return self._cached_loaders
  26
+
  27
+    def find_template(self, name, dirs=None):
  28
+        for loader in self.loaders:
  29
+            try:
  30
+                template, display_name = loader(name, dirs)
  31
+                return (template, make_origin(display_name, loader, name, dirs))
  32
+            except TemplateDoesNotExist:
  33
+                pass
  34
+        raise TemplateDoesNotExist, name
  35
+
  36
+    def load_template(self, template_name, template_dirs=None):
  37
+        if template_name not in self.template_cache:
  38
+            template, origin = self.find_template(template_name, template_dirs)
  39
+            if not hasattr(template, 'render'):
  40
+                template = get_template_from_string(template, origin, template_name)
  41
+            self.template_cache[template_name] = (template, origin)
  42
+        return self.template_cache[template_name]
  43
+
  44
+    def reset(self):
  45
+        "Empty the template cache."
  46
+        self.template_cache.clear()
40  django/template/loaders/eggs.py
@@ -6,20 +6,34 @@
6 6
     resource_string = None
7 7
 
8 8
 from django.template import TemplateDoesNotExist
  9
+from django.template.loader import BaseLoader
9 10
 from django.conf import settings
10 11
 
11  
-def load_template_source(template_name, template_dirs=None):
12  
-    """
13  
-    Loads templates from Python eggs via pkg_resource.resource_string.
  12
+class Loader(BaseLoader):
  13
+    is_usable = resource_string is not None
  14
+
  15
+    def load_template_source(self, template_name, template_dirs=None):
  16
+        """
  17
+        Loads templates from Python eggs via pkg_resource.resource_string.
  18
+
  19
+        For every installed app, it tries to get the resource (app, template_name).
  20
+        """
  21
+        if resource_string is not None:
  22
+            pkg_name = 'templates/' + template_name
  23
+            for app in settings.INSTALLED_APPS:
  24
+                try:
  25
+                    return (resource_string(app, pkg_name).decode(settings.FILE_CHARSET), 'egg:%s:%s' % (app, pkg_name))
  26
+                except:
  27
+                    pass
  28
+        raise TemplateDoesNotExist, template_name
14 29
 
15  
-    For every installed app, it tries to get the resource (app, template_name).
16  
-    """
17  
-    if resource_string is not None:
18  
-        pkg_name = 'templates/' + template_name
19  
-        for app in settings.INSTALLED_APPS:
20  
-            try:
21  
-                return (resource_string(app, pkg_name).decode(settings.FILE_CHARSET), 'egg:%s:%s' % (app, pkg_name))
22  
-            except:
23  
-                pass
24  
-    raise TemplateDoesNotExist, template_name
  30
+_loader = Loader()
  31
+
  32
+def load_template_source(template_name, template_dirs=None):
  33
+    import warnings
  34
+    warnings.warn(
  35
+        "'django.template.loaders.eggs.load_template_source' is deprecated; use 'django.template.loaders.eggs.Loader' instead.",
  36
+        PendingDeprecationWarning
  37
+    )
  38
+    return _loader.load_template_source(template_name, template_dirs)
25 39
 load_template_source.is_usable = resource_string is not None
80  django/template/loaders/filesystem.py
@@ -4,38 +4,58 @@
4 4
 
5 5
 from django.conf import settings
6 6
 from django.template import TemplateDoesNotExist
  7
+from django.template.loader import BaseLoader
7 8
 from django.utils._os import safe_join
8 9
 
9  
-def get_template_sources(template_name, template_dirs=None):
10  
-    """
11  
-    Returns the absolute paths to "template_name", when appended to each
12  
-    directory in "template_dirs". Any paths that don't lie inside one of the
13  
-    template dirs are excluded from the result set, for security reasons.
14  
-    """
15  
-    if not template_dirs:
16  
-        template_dirs = settings.TEMPLATE_DIRS
17  
-    for template_dir in template_dirs:
18  
-        try:
19  
-            yield safe_join(template_dir, template_name)
20  
-        except UnicodeDecodeError:
21  
-            # The template dir name was a bytestring that wasn't valid UTF-8.
22  
-            raise
23  
-        except ValueError:
24  
-            # The joined path was located outside of this particular
25  
-            # template_dir (it might be inside another one, so this isn't
26  
-            # fatal).
27  
-            pass
  10
+class Loader(BaseLoader):
  11
+    is_usable = True
  12
+
  13
+    def get_template_sources(self, template_name, template_dirs=None):
  14
+        """
  15
+        Returns the absolute paths to "template_name", when appended to each
  16
+        directory in "template_dirs". Any paths that don't lie inside one of the
  17
+        template dirs are excluded from the result set, for security reasons.
  18
+        """
  19
+        if not template_dirs:
  20
+            template_dirs = settings.TEMPLATE_DIRS
  21
+        for template_dir in template_dirs:
  22
+            try:
  23
+                yield safe_join(template_dir, template_name)
  24
+            except UnicodeDecodeError:
  25
+                # The template dir name was a bytestring that wasn't valid UTF-8.
  26
+                raise
  27
+            except ValueError:
  28
+                # The joined path was located outside of this particular
  29
+                # template_dir (it might be inside another one, so this isn't
  30
+                # fatal).
  31
+                pass
  32
+
  33
+    def load_template_source(self, template_name, template_dirs=None):
  34
+        tried = []
  35
+        for filepath in self.get_template_sources(template_name, template_dirs):
  36
+            try:
  37
+                file = open(filepath)
  38
+                try:
  39
+                    return (file.read().decode(settings.FILE_CHARSET), filepath)
  40
+                finally:
  41
+                    file.close()
  42
+            except IOError:
  43
+                tried.append(filepath)
  44
+        if tried:
  45
+            error_msg = "Tried %s" % tried
  46
+        else:
  47
+            error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
  48
+        raise TemplateDoesNotExist, error_msg
  49
+    load_template_source.is_usable = True
  50
+
  51
+_loader = Loader()
28 52
 
29 53
 def load_template_source(template_name, template_dirs=None):
30  
-    tried = []
31  
-    for filepath in get_template_sources(template_name, template_dirs):
32  
-        try:
33  
-            return (open(filepath).read().decode(settings.FILE_CHARSET), filepath)
34  
-        except IOError:
35  
-            tried.append(filepath)
36  
-    if tried:
37  
-        error_msg = "Tried %s" % tried
38  
-    else:
39  
-        error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
40  
-    raise TemplateDoesNotExist, error_msg
  54
+    # For backwards compatibility
  55
+    import warnings
  56
+    warnings.warn(
  57
+        "'django.template.loaders.filesystem.load_template_source' is deprecated; use 'django.template.loaders.filesystem.Loader' instead.",
  58
+        PendingDeprecationWarning
  59
+    )
  60
+    return _loader.load_template_source(template_name, template_dirs)
41 61
 load_template_source.is_usable = True
6  django/test/utils.py
@@ -37,8 +37,8 @@ def setup_test_environment():
37 37
         - Set the email backend to the locmem email backend.
38 38
         - Setting the active locale to match the LANGUAGE_CODE setting.
39 39
     """
40  
-    Template.original_render = Template.render
41  
-    Template.render = instrumented_test_render
  40
+    Template.original_render = Template._render
  41
+    Template._render = instrumented_test_render
42 42
 
43 43
     mail.original_SMTPConnection = mail.SMTPConnection
44 44
     mail.SMTPConnection = locmem.EmailBackend
@@ -57,7 +57,7 @@ def teardown_test_environment():
57 57
         - Restoring the email sending functions
58 58
 
59 59
     """
60  
-    Template.render = Template.original_render
  60
+    Template._render = Template.original_render
61 61
     del Template.original_render
62 62
 
63 63
     mail.SMTPConnection = mail.original_SMTPConnection
6  django/views/debug.py
@@ -76,8 +76,12 @@ def get_traceback_html(self):
76 76
                         for t in source_list_func(str(self.exc_value))]
77 77
                 except (ImportError, AttributeError):
78 78
                     template_list = []
  79
+                if hasattr(loader, '__class__'):
  80
+                    loader_name = loader.__module__ + '.' + loader.__class__.__name__
  81
+                else:
  82
+                    loader_name = loader.__module__ + '.' + loader.__name__
79 83
                 self.loader_debug_info.append({
80  
-                    'loader': loader.__module__ + '.' + loader.__name__,
  84
+                    'loader': loader_name,
81 85
                     'templates': template_list,
82 86
                 })
83 87
         if settings.TEMPLATE_DEBUG and hasattr(self.exc_value, 'source'):
79  docs/howto/custom-template-tags.txt
@@ -463,6 +463,85 @@ new ``Context`` in this example, the results would have *always* been
463 463
 automatically escaped, which may not be the desired behavior if the template
464 464
 tag is used inside a ``{% autoescape off %}`` block.
465 465
 
  466
+.. _template_tag_thread_safety:
  467
+
  468
+Thread-safety considerations
  469
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  470
+
  471
+.. versionadded:: 1.2
  472
+
  473
+Once a node is parsed, its ``render`` method may be called any number of times.
  474
+Since Django is sometimes run in multi-threaded environments, a single node may
  475
+be simultaneously rendering with different contexts in response to two separate
  476
+requests. Therefore, it's important to make sure your template tags are thread
  477
+safe.
  478
+
  479
+To make sure your template tags are thread safe, you should never store state
  480
+information on the node itself. For example, Django provides a builtin ``cycle``
  481
+template tag that cycles among a list of given strings each time it's rendered::
  482
+
  483
+    {% for o in some_list %}
  484
+        <tr class="{% cycle 'row1' 'row2' %}>
  485
+            ...
  486
+        </tr>
  487
+    {% endfor %}
  488
+
  489
+A naive implementation of ``CycleNode`` might look something like this::
  490
+
  491
+    class CycleNode(Node):
  492
+        def __init__(self, cyclevars):
  493
+            self.cycle_iter = itertools.cycle(cyclevars)
  494
+        def render(self, context):
  495
+            return self.cycle_iter.next()
  496
+
  497
+But, suppose we have two templates rendering the template snippet from above at
  498
+the same time:
  499
+
  500
+    1. Thread 1 performs its first loop iteration, ``CycleNode.render()``
  501
+       returns 'row1'
  502
+    2. Thread 2 performs its first loop iteration, ``CycleNode.render()``
  503
+       returns 'row2'
  504
+    3. Thread 1 performs its second loop iteration, ``CycleNode.render()``
  505
+       returns 'row1'
  506
+    4. Thread 2 performs its second loop iteration, ``CycleNode.render()``
  507
+       returns 'row2'
  508
+
  509
+The CycleNode is iterating, but it's iterating globally. As far as Thread 1
  510
+and Thread 2 are concerned, it's always returning the same value. This is
  511
+obviously not what we want!
  512
+
  513
+To address this problem, Django provides a ``render_context`` that's associated
  514
+with the ``context`` of the template that is currently being rendered. The
  515
+``render_context`` behaves like a Python dictionary, and should be used to store
  516
+``Node`` state between invocations of the ``render`` method.
  517
+
  518
+Let's refactor our ``CycleNode`` implementation to use the ``render_context``::
  519
+
  520
+    class CycleNode(Node):
  521
+        def __init__(self, cyclevars):
  522
+            self.cyclevars = cyclevars
  523
+        def render(self, context):
  524
+            if self not in context.render_context:
  525
+                context.render_context[self] = itertools.cycle(self.cyclevars)
  526
+            cycle_iter = context.render_context[self]
  527
+            return cycle_iter.next()
  528
+
  529
+Note that it's perfectly safe to store global information that will not change
  530
+throughout the life of the ``Node`` as an attribute. In the case of
  531
+``CycleNode``, the ``cyclevars`` argument doesn't change after the ``Node`` is
  532
+instantiated, so we don't need to put it in the ``render_context``. But state
  533
+information that is specific to the template that is currently being rendered,
  534
+like the current iteration of the ``CycleNode``, should be stored in the
  535
+``render_context``.
  536
+
  537
+.. note::
  538
+    Notice how we used ``self`` to scope the ``CycleNode`` specific information
  539
+    within the ``render_context``. There may be multiple ``CycleNodes`` in a
  540
+    given template, so we need to be careful not to clobber another node's state
  541
+    information. The easiest way to do this is to always use ``self`` as the key
  542
+    into ``render_context``. If you're keeping track of several state variables,
  543
+    make ``render_context[self]`` a dictionary.
  544
+
466 545
 Registering the tag
467 546
 ~~~~~~~~~~~~~~~~~~~
468 547
 
10  docs/internals/deprecation.txt
@@ -36,14 +36,20 @@ their deprecation, as per the :ref:`Django deprecation policy
36 36
           manager in the ``User`` model (``user.message_set``), and the
37 37
           associated methods (``user.message_set.create()`` and
38 38
           ``user.get_and_delete_messages()``), which have
39  
-          been deprecated since the 1.2 release, will be removed.  The 
40  
-          :ref:`messages framework <ref-contrib-messages>` should be used 
  39
+          been deprecated since the 1.2 release, will be removed.  The
  40
+          :ref:`messages framework <ref-contrib-messages>` should be used
41 41
           instead.
42 42
 
43 43
         * Authentication backends need to support the ``obj`` parameter for
44 44
           permission checking. The ``supports_object_permissions`` variable
45 45
           is not checked any longer and can be removed.
46 46
 
  47
+        * The ability to specify a callable template loader rather than a
  48
+          ``Loader`` class will be removed, as will the ``load_template_source``
  49
+          functions that are included with the built in template loaders for
  50
+          backwards compatibility. These have been deprecated since the 1.2
  51
+          release.
  52
+
47 53
     * 2.0
48 54
         * ``django.views.defaults.shortcut()``. This function has been moved
49 55
           to ``django.contrib.contenttypes.views.shortcut()`` as part of the
4  docs/ref/contrib/sitemaps.txt
@@ -36,7 +36,7 @@ To install the sitemap app, follow these steps:
36 36
     1. Add ``'django.contrib.sitemaps'`` to your :setting:`INSTALLED_APPS`
37 37
        setting.
38 38
        
39  
-    2. Make sure ``'django.template.loaders.app_directories.load_template_source'``
  39
+    2. Make sure ``'django.template.loaders.app_directories.Loader'``
40 40
        is in your :setting:`TEMPLATE_LOADERS` setting. It's in there by default,
41 41
        so you'll only need to change this if you've changed that setting.
42 42
 
@@ -45,7 +45,7 @@ To install the sitemap app, follow these steps:
45 45
 
46 46
 (Note: The sitemap application doesn't install any database tables. The only
47 47
 reason it needs to go into :setting:`INSTALLED_APPS` is so that the
48  
-:func:`~django.template.loaders.app_directories.load_template_source` template
  48
+:func:`~django.template.loaders.app_directories.Loader` template
49 49
 loader can find the default templates.)
50 50
 
51 51
 Initialization
13  docs/ref/settings.txt
@@ -819,7 +819,7 @@ MESSAGE_LEVEL
819 819
 
820 820
 Default: `messages.INFO`
821 821
 
822  
-Sets the minimum message level that will be recorded by the messages 
  822
+Sets the minimum message level that will be recorded by the messages
823 823
 framework. See the :ref:`messages documentation <ref-contrib-messages>` for
824 824
 more details.
825 825
 
@@ -1150,11 +1150,14 @@ TEMPLATE_LOADERS
1150 1150
 
1151 1151
 Default::
1152 1152
 
1153  
-     ('django.template.loaders.filesystem.load_template_source',
1154  
-      'django.template.loaders.app_directories.load_template_source')
  1153
+     ('django.template.loaders.filesystem.Loader',
  1154
+      'django.template.loaders.app_directories.Loader')
1155 1155
 
1156  
-A tuple of callables (as strings) that know how to import templates from
1157  
-various sources. See :ref:`ref-templates-api`.
  1156
+A tuple of template loader classes, specified as strings. Each ``Loader`` class
  1157
+knows how to import templates from a particular sources. Optionally, a tuple can be
  1158
+used instead of a string. The first item in the tuple should be the ``Loader``'s
  1159
+module, subsequent items are passed to the ``Loader`` during initialization. See
  1160
+:ref:`ref-templates-api`.
1158 1161
 
1159 1162
 .. setting:: TEMPLATE_STRING_IF_INVALID
1160 1163
 
108  docs/ref/templates/api.txt
@@ -322,7 +322,7 @@ and return a dictionary of items to be merged into the context. By default,
322 322
    cannot be turned off by the :setting:`TEMPLATE_CONTEXT_PROCESSORS` setting.
323 323
 
324 324
 .. versionadded:: 1.2
325  
-   The ``'messages'`` context processor was added.  For more information, see 
  325
+   The ``'messages'`` context processor was added.  For more information, see
326 326
    the :ref:`messages documentation <ref-contrib-messages>`.
327 327
 
328 328
 Each processor is applied in order. That means, if one processor adds a
@@ -379,7 +379,7 @@ If :setting:`TEMPLATE_CONTEXT_PROCESSORS` contains this processor, every
379 379
 
380 380
 .. versionchanged:: 1.2
381 381
    Prior to version 1.2, the ``messages`` variable was a lazy accessor for
382  
-   ``user.get_and_delete_messages()``. It has been changed to include any 
  382
+   ``user.get_and_delete_messages()``. It has been changed to include any
383 383
    messages added via the :ref:`messages framework <ref-contrib-messages`.
384 384
 
385 385
 django.core.context_processors.debug
@@ -448,7 +448,7 @@ If :setting:`TEMPLATE_CONTEXT_PROCESSORS` contains this processor, every
448 448
    context processor.  For backwards compatibility the ``'auth'`` context
449 449
    processor will continue to supply the ``messages`` variable until Django
450 450
    1.4.  If you use the ``messages`` variable, your project will work with
451  
-   either (or both) context processors, but it is recommended to add 
  451
+   either (or both) context processors, but it is recommended to add
452 452
    ``django.contrib.messages.context_processors.messages`` so your project
453 453
    will be prepared for the future upgrade.
454 454
 
@@ -571,11 +571,11 @@ by editing your :setting:`TEMPLATE_LOADERS` setting. :setting:`TEMPLATE_LOADERS`
571 571
 should be a tuple of strings, where each string represents a template loader.
572 572
 Here are the template loaders that come with Django:
573 573
 
574  
-``django.template.loaders.filesystem.load_template_source``
  574
+``django.template.loaders.filesystem.Loader``
575 575
     Loads templates from the filesystem, according to :setting:`TEMPLATE_DIRS`.
576 576
     This loader is enabled by default.
577 577
 
578  
-``django.template.loaders.app_directories.load_template_source``
  578
+``django.template.loaders.app_directories.Loader``
579 579
     Loads templates from Django apps on the filesystem. For each app in
580 580
     :setting:`INSTALLED_APPS`, the loader looks for a ``templates``
581 581
     subdirectory. If the directory exists, Django looks for templates in there.
@@ -599,12 +599,43 @@ Here are the template loaders that come with Django:
599 599
 
600 600
     This loader is enabled by default.
601 601
 
602  
-``django.template.loaders.eggs.load_template_source``
  602
+``django.template.loaders.eggs.Loader``
603 603
     Just like ``app_directories`` above, but it loads templates from Python
604 604
     eggs rather than from the filesystem.
605 605
 
606 606
     This loader is disabled by default.
607 607
 
  608
+``django.template.loaders.cached.Loader``
  609
+    By default, the templating system will read and compile your templates every
  610
+    time they need to be rendered. While the Django templating system is quite
  611
+    fast, the overhead from reading and compiling templates can add up.
  612
+
  613
+    The cached template loader is a class-based loader that you configure with
  614
+    a list of other loaders that it should wrap. The wrapped loaders are used to
  615
+    locate unknown templates when they are first encountered. The cached loader
  616
+    then stores the compiled ``Template`` in memory. The cached ``Template``
  617
+    instance is returned for subsequent requests to load the same template.
  618
+
  619
+    For example, to enable template caching with the ``filesystem`` and
  620
+    ``app_directories`` template loaders you might use the following settings::
  621
+
  622
+        TEMPLATE_LOADERS = (
  623
+            ('django.template.loaders.cached.Loader', (
  624
+                'django.template.loaders.filesystem.Loader',
  625
+                'django.template.loaders.app_directories.Loader',
  626
+            )),
  627
+        )
  628
+
  629
+    .. note::
  630
+        All of the built-in Django template tags are safe to use with the cached
  631
+        loader, but if you're using custom template tags that come from third
  632
+        party packages, or that you wrote yourself, you should ensure that the
  633
+        ``Node`` implementation for each tag is thread-safe. For more
  634
+        information, see
  635
+        :ref:`template tag thread safety considerations<template_tag_thread_safety>`.
  636
+
  637
+    This loader is disabled by default.
  638
+
608 639
 Django uses the template loaders in order according to the
609 640
 :setting:`TEMPLATE_LOADERS` setting. It uses each loader until a loader finds a
610 641
 match.
@@ -667,3 +698,68 @@ settings you wish to specify. You might want to consider setting at least
667 698
 and :setting:`TEMPLATE_DEBUG`. All available settings are described in the
668 699
 :ref:`settings documentation <ref-settings>`, and any setting starting with
669 700
 ``TEMPLATE_`` is of obvious interest.
  701
+
  702
+.. _topic-template-alternate-language:
  703
+
  704
+Using an alternative template language
  705
+======================================
  706
+
  707
+.. versionadded 1.2
  708
+
  709
+The Django ``Template`` and ``Loader`` classes implement a simple API for
  710
+loading and rendering templates. By providing some simple wrapper classes that
  711
+implement this API we can use third party template systems like `Jinja2
  712
+<http://jinja.pocoo.org/2/>`_ or `Cheetah <http://www.cheetahtemplate.org/>`_. This
  713
+allows us to use third-party template libraries without giving up useful Django
  714
+features like the Django ``Context`` object and handy shortcuts like
  715
+``render_to_response()``.
  716
+
  717
+The core component of the Django templating system is the ``Template`` class.
  718
+This class has a very simple interface: it has a constructor that takes a single
  719
+positional argument specifying the template string, and a ``render()`` method
  720
+that takes a ``django.template.context.Context`` object and returns a string
  721
+containing the rendered response.
  722
+
  723
+Suppose we're using a template language that defines a ``Template`` object with
  724
+a ``render()`` method that takes a dictionary rather than a ``Context`` object.
  725
+We can write a simple wrapper that implements the Django ``Template`` interface::
  726
+
  727
+    import some_template_language
  728
+    class Template(some_template_language.Template):
  729
+        def render(self, context):
  730
+            # flatten the Django Context into a single dictionary.
  731
+            context_dict = {}
  732
+            for d in context.dicts:
  733
+                context_dict.update(d)
  734
+            return super(Template, self).render(context_dict)
  735
+
  736
+That's all that's required to make our fictional ``Template`` class compatible
  737
+with the Django loading and rendering system!
  738
+
  739
+The next step is to write a ``Loader`` class that returns instances of our custom
  740
+template class instead of the default ``django.template.Template``. Custom ``Loader``
  741
+classes should inherit from ``django.template.loader.BaseLoader`` and override
  742
+the ``load_template_source()`` method, which takes a ``template_name`` argument,
  743
+loads the template from disk (or elsewhere), and returns a tuple:
  744
+``(template_string, template_origin)``.
  745
+
  746
+The ``load_template()`` method of the ``Loader`` class retrieves the template
  747
+string by calling ``load_template_source()``, instantiates a ``Template`` from
  748
+the template source, and returns a tuple: ``(template, template_origin)``. Since
  749
+this is the method that actually instantiates the ``Template``, we'll need to
  750
+override it to use our custom template class instead. We can inherit from the
  751
+builtin ``django.template.loaders.app_directories.Loader`` to take advantage of
  752
+the ``load_template_source()`` method implemented there::
  753
+
  754
+    from django.template.loaders import app_directories
  755
+    class Loader(app_directories.Loader):
  756
+        is_usable = True
  757
+
  758
+        def load_template(self, template_name, template_dirs=None):
  759
+            source, origin = self.load_template_source(template_name, template_dirs)
  760
+            template = Template(source)
  761
+            return template, origin
  762
+
  763
+Finally, we need to modify our project settings, telling Django to use our custom
  764
+loader. Now we can write all of our templates in our alternative template
  765
+language while continuing to use the rest of the Django templating system.
42  docs/releases/1.2.txt
@@ -76,6 +76,19 @@ changes:
76 76
 
77 77
        __members__ = property(lambda self: self.__dir__())
78 78
 
  79
+Stateful template tags
  80