Ticket #1292: loader_caching_fix_r2158.diff

File loader_caching_fix_r2158.diff, 2.6 KB (added by django@…, 19 years ago)

Fix for template loader

  • django/core/template/loader.py

     
    2424from django.core.template import Origin, StringOrigin, Template, Context, TemplateDoesNotExist, add_to_builtins
    2525from django.conf.settings import TEMPLATE_LOADERS, TEMPLATE_DEBUG
    2626
    27 template_source_loaders = []
    28 for path in TEMPLATE_LOADERS:
    29     i = path.rfind('.')
    30     module, attr = path[:i], path[i+1:]
    31     try:
    32         mod = __import__(module, globals(), locals(), [attr])
    33     except ImportError, e:
    34         raise ImproperlyConfigured, 'Error importing template source loader %s: "%s"' % (module, e)
    35     try:
    36         func = getattr(mod, attr)
    37     except AttributeError:
    38         raise ImproperlyConfigured, 'Module "%s" does not define a "%s" callable template source loader' % (module, attr)
    39     if not func.is_usable:
    40         import warnings
    41         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)
    42     else:
    43         template_source_loaders.append(func)
    44 
    4527class LoaderOrigin(Origin):
    4628    def __init__(self, display_name, loader, name, dirs):
    4729        super(LoaderOrigin, self).__init__(display_name)
     
    5739        return None
    5840
    5941def find_template_source(name, dirs=None):
     42    global template_source_loaders
     43    if not 'template_source_loaders' in globals():
     44        template_source_loaders = []
     45        for path in TEMPLATE_LOADERS:
     46            i = path.rfind('.')
     47            module, attr = path[:i], path[i+1:]
     48            try:
     49                mod = __import__(module, globals(), locals(), [attr])
     50            except ImportError, e:
     51                raise ImproperlyConfigured, 'Error importing template source loader %s: "%s"' % (module, e)
     52            try:
     53                func = getattr(mod, attr)
     54            except AttributeError:
     55                raise ImproperlyConfigured, 'Module "%s" does not define a "%s" callable template source loader' % (module, attr)
     56            if not func.is_usable:
     57                import warnings
     58                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)
     59            else:
     60                template_source_loaders.append(func)
    6061    for loader in template_source_loaders:
    6162        try:
    6263            source, display_name = loader(name, dirs)
Back to Top