def get_template(template_name):
    """
    Returns a compiled Template object for the given template name,
    in any of the template languages listed in settings.TEMPLATE_LANGUAGES,
    looking for each through the directories specified in
    settings.<LANGNAME>_TEMPLATE_DIRS (except for Django templates, which use
    settings.TEMPLATE_DIRS).
    """
    source = None
    languages=getattr(settings, 'TEMPLATE_LANGUAGES', None)

    if languages is None:
        return _original_get_template(template_name)

    for lang in languages:
        if lang=='django':
            dirs=None
        else:
            prefix="%s_" % lang.upper() 
            confvar='%sTEMPLATE_DIRS' % prefix
            dirs=getattr(settings, confvar, ())

            if not dirs:
                warnings.warn("no directories defined for template language %r.  Please define the configuration setting %r." % (lang, confvar))
                continue
        try:
            source, origin = find_template_source(template_name, dirs)
        except TemplateDoesNotExist as e:
            continue
        return get_template_from_string(lang, source, origin, template_name)
        
    raise TemplateDoesNotExist, template_name
Example #2
0
 def get_template(template_name):
     for skip_path in getattr(settings, 'KEEP_DJANGO_TEMPLATES', ()):
         if template_name.startswith(skip_path):
             return _original_get_template(template_name)
     return env.get_template(template_name)