Ticket #4278: loader.diff

File loader.diff, 2.0 KB (added by anonymous, 18 years ago)
  • django/template/loader.py

     
    7171            pass
    7272    raise TemplateDoesNotExist, name
    7373
    74 def get_template(template_name):
     74def get_template(template_name, dirs=None):
    7575    """
    7676    Returns a compiled Template object for the given template name,
    7777    handling template inheritance recursively.
    7878    """
    79     source, origin = find_template_source(template_name)
     79    source, origin = find_template_source(template_name, dirs)
    8080    template = get_template_from_string(source, origin, template_name)
    8181    return template
    8282
     
    8787    """
    8888    return Template(source, origin, name)
    8989
    90 def render_to_string(template_name, dictionary=None, context_instance=None):
     90def render_to_string(template_name, dictionary=None, context_instance=None, dirs=None):
    9191    """
    9292    Loads the given template_name and renders it with the given dictionary as
    9393    context. The template_name may be a string to load a single template using
     
    9696    """
    9797    dictionary = dictionary or {}
    9898    if isinstance(template_name, (list, tuple)):
    99         t = select_template(template_name)
     99        t = select_template(template_name, dirs)
    100100    else:
    101         t = get_template(template_name)
     101        t = get_template(template_name, dirs)
    102102    if context_instance:
    103103        context_instance.update(dictionary)
    104104    else:
    105105        context_instance = Context(dictionary)
    106106    return t.render(context_instance)
    107107
    108 def select_template(template_name_list):
     108def select_template(template_name_list, dirs=None):
    109109    "Given a list of template names, returns the first that can be loaded."
    110110    for template_name in template_name_list:
    111111        try:
    112             return get_template(template_name)
     112            return get_template(template_name, dirs)
    113113        except TemplateDoesNotExist:
    114114            continue
    115115    # If we get here, none of the templates could be loaded
Back to Top