Ticket #4278: template-dirs.diff

File template-dirs.diff, 2.3 KB (added by Adam Vandenberg, 14 years ago)

Rebase on trunk.

  • django/template/loader.py

    diff --git a/django/template/loader.py b/django/template/loader.py
    index 9ba0f2c..72e9248 100644
    a b def find_template_source(name, dirs=None):  
    149149        raise Exception("Found a compiled template that is incompatible with the deprecated `django.template.loaders.find_template_source` function.")
    150150    return template, origin
    151151
    152 def get_template(template_name):
     152def get_template(template_name, dirs=None):
    153153    """
    154154    Returns a compiled Template object for the given template name,
    155155    handling template inheritance recursively.
    156156    """
    157     template, origin = find_template(template_name)
     157    template, origin = find_template(template_name, dirs)
    158158    if not hasattr(template, 'render'):
    159159        # template needs to be compiled
    160160        template = get_template_from_string(template, origin, template_name)
    def get_template_from_string(source, origin=None, name=None):  
    167167    """
    168168    return Template(source, origin, name)
    169169
    170 def render_to_string(template_name, dictionary=None, context_instance=None):
     170def render_to_string(template_name, dictionary=None, context_instance=None, dirs=None):
    171171    """
    172172    Loads the given template_name and renders it with the given dictionary as
    173173    context. The template_name may be a string to load a single template using
    def render_to_string(template_name, dictionary=None, context_instance=None):  
    176176    """
    177177    dictionary = dictionary or {}
    178178    if isinstance(template_name, (list, tuple)):
    179         t = select_template(template_name)
     179        t = select_template(template_name, dirs)
    180180    else:
    181         t = get_template(template_name)
     181        t = get_template(template_name, dirs)
    182182    if context_instance:
    183183        context_instance.update(dictionary)
    184184    else:
    185185        context_instance = Context(dictionary)
    186186    return t.render(context_instance)
    187187
    188 def select_template(template_name_list):
     188def select_template(template_name_list, dirs=None):
    189189    "Given a list of template names, returns the first that can be loaded."
    190190    for template_name in template_name_list:
    191191        try:
    192             return get_template(template_name)
     192            return get_template(template_name, dirs)
    193193        except TemplateDoesNotExist:
    194194            continue
    195195    # If we get here, none of the templates could be loaded
Back to Top