Ticket #8116: 8116-r11637-IncludedTemplateDoesNotExist.diff

File 8116-r11637-IncludedTemplateDoesNotExist.diff, 2.0 KB (added by Antti Kaihola, 15 years ago)

patch: included templates throw a different exception

  • django/template/__init__.py

    diff --git a/django/template/__init__.py b/django/template/__init__.py
    index 5493e5b..6ed6bdd 100644
    a b class TemplateSyntaxError(Exception):  
    121121class TemplateDoesNotExist(Exception):
    122122    pass
    123123
     124class IncludedTemplateDoesNotExist(TemplateDoesNotExist):
     125    pass
     126
    124127class TemplateEncodingError(Exception):
    125128    pass
    126129
  • django/template/loader.py

    diff --git a/django/template/loader.py b/django/template/loader.py
    index 8195c4b..3a76ce5 100644
    a b  
    2121# installed, because pkg_resources is necessary to read eggs.
    2222
    2323from django.core.exceptions import ImproperlyConfigured
    24 from django.template import Origin, Template, Context, TemplateDoesNotExist, add_to_builtins
     24from django.template import Origin, Template, Context, TemplateDoesNotExist, IncludedTemplateDoesNotExist, add_to_builtins
    2525from django.utils.importlib import import_module
    2626from django.conf import settings
    2727
    def get_template(template_name):  
    7979    handling template inheritance recursively.
    8080    """
    8181    source, origin = find_template_source(template_name)
    82     template = get_template_from_string(source, origin, template_name)
     82    try:
     83        template = get_template_from_string(source, origin, template_name)
     84    except TemplateDoesNotExist, included_template_name:
     85        raise IncludedTemplateDoesNotExist, included_template_name
    8386    return template
    8487
    8588def get_template_from_string(source, origin=None, name=None):
    def select_template(template_name_list):  
    112115    for template_name in template_name_list:
    113116        try:
    114117            return get_template(template_name)
    115         except TemplateDoesNotExist:
     118        except TemplateDoesNotExist, e:
     119            if isinstance(e, IncludedTemplateDoesNotExist):
     120                raise
    116121            continue
    117122    # If we get here, none of the templates could be loaded
    118123    raise TemplateDoesNotExist, ', '.join(template_name_list)
Back to Top