Load a templatetag library on multiple Django versions.

    Returns None if the library isn't loaded.
488607
def load_tag_library(libname):
    
    from django.template.backends.django import get_installed_libraries
    from django.template.library import InvalidTemplateLibrary
    try:
        lib = get_installed_libraries()[libname]
        lib = importlib.import_module(lib).register
        return lib
    except (InvalidTemplateLibrary, KeyError):
        return None
788696
def get_template(self, context, **kwargs):
        
        if 'template' in kwargs['params']:
            self.template = kwargs['params']['template']
        return super(GoscaleTemplateInclusionTag, self).get_template(context, **kwargs)
696835
def load_template(self, name):
        
        # hopefully speeds up loading of templates a little, especially when loaded multiple times
        if name in self.cached_templates:
            logger.debug("Using cached template: %s", name)
            return self.cached_templates[name]

        logger.debug("Attempting to find template by name: %s", name)
        name_with_ext, provider_name, base_path = self.find_template_details(name)

        full_path = None
        if base_path is not None:
            full_path = os.path.join(base_path, name_with_ext)

        # load it with the relevant provider
        template = template_exception_handler(
            lambda: self.get_provider(provider_name).load_template(
                name_with_ext,
                full_path=full_path
            ),
            self.error_context,
            filename=full_path
        )

        # cache it for potential later use
        self.cached_templates[name] = template
        return template
567072
def load_library(version):
    
    check_version(version)
    module_name = SUPPORTED_LIBRARIES[version]
    lib = sys.modules.get(module_name)
    if lib is None:
        lib = importlib.import_module(module_name)
    return lib
474863
static IdentityTemplateLibrary loadFromResource(String resource) {
        InputStream in = IdentityTemplateLibrary.class.getResourceAsStream(resource);
        try {
            return load(in);
        } catch (IOException e) {
            throw new IllegalArgumentException("Could not load template library from resource " + resource, e);
        } finally {
            try {
                if (in != null) in.close();
            } catch (IOException e) {
                // ignored
            }
        }
    }
372412
def page_templates_loading_check(app_configs, **kwargs):
    
    errors = []

    for page_template in settings.get_page_templates():
        try:
            loader.get_template(page_template[0])
        except template.TemplateDoesNotExist:
            errors.append(checks.Warning(
                    'Django cannot find template %s' % page_template[0],
                    obj=page_template, id='pages.W001'))

    return errors
594056
def render(template_name, extra_environments=None, **kwargs):
    
    if extra_environments is None:
        extra_environments = {}
    default_loader = PackageLoader('dodotable', 'templates')
    loader = extra_environments.get(
        'template_loader',
        default_loader)
    if not loader:
        loader = default_loader
    get_translations = extra_environments.get('get_translations')
    env = Environment(loader=loader,
                      extensions=['jinja2.ext.i18n', 'jinja2.ext.with_'],
                      autoescape=True)
    env.globals.update(extra_environments)
    translations = get_translations() if callable(get_translations) else None
    if translations is None:
        translations = gettext.NullTranslations()
    env.install_gettext_translations(translations)
    template = env.get_template(template_name)
    return template.render(**kwargs)
276465
def load_template_source(template_name, template_dirs=None):
    """"""
    template_zipfiles = getattr(settings, "TEMPLATE_ZIP_FILES", [])

    # Try each ZIP file in TEMPLATE_ZIP_FILES.
    for fname in template_zipfiles:
        try:
            z = zipfile.ZipFile(fname)
            source = z.read(template_name)
        except (IOError, KeyError):
            continue
        z.close()
        # We found a template, so return the source.
        template_path = "%s:%s" % (fname, template_name)
        return (source, template_path)

    # If we reach here, the template couldn't be loaded
    raise TemplateDoesNotExist(template_name)
285822
def get_template_loader(app, subdir='templates'):
    '''
    
    '''
    dmp = apps.get_app_config('django_mako_plus')
    return dmp.engine.get_template_loader(app, subdir, create=True)
53794
def get_templates(self, context, template_name=None):
        "  "
        if not template_name:
            template_name = self.template_name

        kw = {}
        if 'object' in context:
            o = context['object']
            kw['slug'] = o.slug

        if context.get('content_type', False):
            ct = context['content_type']
            kw['app_label'] = ct.app_label
            kw['model_label'] = ct.model

        return get_templates(template_name, category=context['category'], **kw)
407118
def get_template(template_name, using=None):
    
    engines = _engine_list(using)
    for engine in engines:
        try:
            return engine.get_template(template_name)
        except TemplateDoesNotExist as e:
            pass

    raise TemplateDoesNotExist(template_name)
87452
def generate_template(template_name, **context):
    """"""
    context.update(href=href, format_datetime=format_datetime)
    return template_loader.load(template_name).generate(**context)
279215
def tag(request, tag_id=None):
    
    html = get_tag_html(tag_id)
    t = template.Template(html)
    c = template.RequestContext(request)

    return HttpResponse(t.render(c))
413910
def __get_view_tmpl(tag_key):
    '''
    
    '''
    the_view_file_4 = './templates/tmpl_{0}/tpl_view_{1}.html'.format(
        KIND_DICS['kind_' + tag_key.split('_')[-1]],
        tag_key.split('_')[1]
    )
    the_view_file_2 = './templates/tmpl_{0}/tpl_view_{1}.html'.format(
        KIND_DICS['kind_' + tag_key.split('_')[-1]],
        tag_key.split('_')[1][:2]
    )
    if os.path.exists(the_view_file_4):
        the_view_sig_str = '_{0}'.format(tag_key.split('_')[1])
    elif os.path.exists(the_view_file_2):
        the_view_sig_str = '_{0}'.format(tag_key.split('_')[1][:2])
    else:
        the_view_sig_str = ''
    return the_view_sig_str
487607
def get_template_loaders():
    
    try:
        from django.template.engine import Engine
    except ImportError:  # Django < 1.8
        Engine = None

    if Engine:
        try:
            engine = Engine.get_default()
        except ImproperlyConfigured:
            loaders = []
        else:
            loaders = engine.template_loaders
    else:  # Django < 1.8
        from django.template.loader import find_template_loader
        loaders = [
            find_template_loader(loader_name)
            for loader_name in settings.TEMPLATE_LOADERS]
    return loaders
1304683
def create_tag(version: Union[Version, str], tag_format: Optional[str] = None):
    
    if isinstance(version, str):
        version = Version(version)

    if not tag_format:
        return version.public

    major, minor, patch = version.release
    prerelease = ""
    if version.is_prerelease:
        prerelease = f"{version.pre[0]}{version.pre[1]}"

    t = Template(tag_format)
    return t.safe_substitute(
        version=version, major=major, minor=minor, patch=patch, prerelease=prerelease
    )
5895
def render_nocache(self):
        
        tmpl = template.Template(''.join([
            # start by loading the cache library
            template.BLOCK_TAG_START,
            'load %s' % self.get_templatetag_module(),
            template.BLOCK_TAG_END,
            # and surround the cached template by "raw" tags
            self.RAW_TOKEN_START,
            self.content,
            self.RAW_TOKEN_END,
        ]))
        return tmpl.render(self.context)