Ticket #9874: template_cache.diff

File template_cache.diff, 2.0 KB (added by novoya, 6 years ago)

templace cache patch

  • django1.02/django/template/loader_tags.py

     
    6161        if hasattr(parent, 'render'):
    6262            return parent # parent is a Template object
    6363        try:
    64             source, origin = find_template_source(parent, self.template_dirs)
     64            return get_template(parent)
    6565        except TemplateDoesNotExist:
    66             raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
    67         else:
    68             return get_template_from_string(source, origin, parent)
     66            raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent       
    6967
    7068    def render(self, context):
    7169        compiled_parent = self.get_parent(context)
  • django1.02/django/template/loader.py

     
    2525from django.conf import settings
    2626
    2727template_source_loaders = None
     28template_cache = {}
    2829
    2930class LoaderOrigin(Origin):
    3031    def __init__(self, display_name, loader, name, dirs):
     
    7778    Returns a compiled Template object for the given template name,
    7879    handling template inheritance recursively.
    7980    """
    80     source, origin = find_template_source(template_name)
    81     template = get_template_from_string(source, origin, template_name)
     81    global template_cache
     82    if template_name in template_cache:
     83        template = template_cache[template_name]
     84    else:
     85        source, origin = find_template_source(template_name)
     86        template = get_template_from_string(source, origin, template_name)
     87        template_cache[template_name] = template
    8288    return template
    8389
    8490def get_template_from_string(source, origin=None, name=None):
Back to Top