How to use the jinja.exceptions.TemplateNotFound function in Jinja

To help you get started, we’ve selected a few Jinja examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pallets / jinja / jinja / plugin.py View on Github external
def render_function(template, values, options):
        if options.get('is_string'):
            tmpl = env.from_string(template)
        else:
            try:
                tmpl = env.get_template(template)
            except TemplateNotFound:
                return
        return tmpl.render(**values)
github pallets / jinja / jinja / loaders.py View on Github external
def get_source(self, environment, name, parent):
        """
        Override this method to get the source for a template.
        """
        raise TemplateNotFound(name)
github pallets / jinja / jinja / loaders.py View on Github external
def parse(self, environment, name, parent):
        for loader in self.loaders:
            try:
                return loader.parse(environment, name, parent)
            except TemplateNotFound, e:
                if e.name != name:
                    raise
                continue
        raise TemplateNotFound(name)
github pallets / jinja / jinja / loaders.py View on Github external
def get_source(self, environment, name, parent):
        rv = self.loader_func(name)
        if rv is None:
            raise TemplateNotFound(name)
        if isinstance(rv, str):
            return rv.decode(environment.template_charset)
        return rv
github sphinx-doc / sphinx / sphinx / _jinja.py View on Github external
def get_source(self, environment, name, parent):
        name = name.replace('/', path.sep)
        if name.startswith('!'):
            name = name[1:]
            if not path.exists(path.join(self.basepath, name)):
                raise TemplateNotFound(name)
            filename = path.join(self.basepath, name)
        elif path.isabs(name):
            if not path.exists(name):
                raise TemplateNotFound(name)
            filename = name
        else:
            for searchpath in self.searchpaths:
                if path.exists(path.join(searchpath, name)):
                    filename = path.join(searchpath, name)
                    break
            else:
                raise TemplateNotFound(name)
        f = codecs.open(filename, 'r', environment.template_charset)
        try:
            return f.read()
        finally:
github sphinx-doc / sphinx / sphinx / _jinja.py View on Github external
if name.startswith('!'):
            name = name[1:]
            if not path.exists(path.join(self.basepath, name)):
                raise TemplateNotFound(name)
            filename = path.join(self.basepath, name)
        elif path.isabs(name):
            if not path.exists(name):
                raise TemplateNotFound(name)
            filename = name
        else:
            for searchpath in self.searchpaths:
                if path.exists(path.join(searchpath, name)):
                    filename = path.join(searchpath, name)
                    break
            else:
                raise TemplateNotFound(name)
        f = codecs.open(filename, 'r', environment.template_charset)
        try:
            return f.read()
        finally:
            f.close()