How to use the jinja2.exceptions.TemplateNotFound function in Jinja2

To help you get started, we’ve selected a few Jinja2 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 splunk / splunk-ref-pas-test / pas_simulated_users_addon / user-api / lib / jinja2 / testsuite / bytecode_cache.py View on Github external
def test_simple(self):
        tmpl = env.get_template('test.html')
        assert tmpl.render().strip() == 'BAR'
        self.assert_raises(TemplateNotFound, env.get_template, 'missing.html')
github splunk / splunk-ref-pas-test / pas_simulated_users_addon / user-api / lib / jinja2 / environment.py View on Github external
.. versionchanged:: 2.4
           If `names` contains a :class:`Template` object it is returned
           from the function unchanged.
        """
        if not names:
            raise TemplatesNotFound(message=u'Tried to select from an empty list '
                                            u'of templates.')
        globals = self.make_globals(globals)
        for name in names:
            if isinstance(name, Template):
                return name
            if parent is not None:
                name = self.join_path(name, parent)
            try:
                return self._load_template(name, globals)
            except TemplateNotFound:
                pass
        raise TemplatesNotFound(names)
github saltstack / salt / tests / unit / modules / test_debian_ip.py View on Github external
'HOSTNAME=Salt\n',
                                      'DOMAIN=saltstack.com\n',
                                      'SEARCH=test.saltstack.com\n'])

                    mock = MagicMock(side_effect=jinja2.exceptions.TemplateNotFound
                                     ('error'))
                    with patch.object(jinja2.Environment, 'get_template', mock):
                        self.assertEqual(debian_ip.build_network_settings(), '')

            with patch.dict(debian_ip.__grains__, {'osfullname': 'Ubuntu',
                                                   'osrelease': '10'}):
                mock = MagicMock(return_value=True)
                with patch.dict(debian_ip.__salt__, {'service.available': mock,
                                                     'service.disable': mock,
                                                     'service.enable': mock}):
                    mock = MagicMock(side_effect=jinja2.exceptions.TemplateNotFound
                                     ('error'))
                    with patch.object(jinja2.Environment, 'get_template', mock):
                        self.assertEqual(debian_ip.build_network_settings(), '')

                    with patch.object(debian_ip, '_read_temp',
                                      MagicMock(return_value=True)):
                        self.assertTrue(debian_ip.build_network_settings
                                        (test='True'))
github pallets / jinja / jinja2 / loaders.py View on Github external
def get_loader(self, template):
        try:
            prefix, name = template.split(self.delimiter, 1)
            loader = self.mapping[prefix]
        except (ValueError, KeyError):
            raise TemplateNotFound(template)
        return loader, name
github zubairghori / Ultimate_todo_list / PART1 / STEP1 - nosql-rest-api / rest-api-nosql / restMongo / lib / python2.7 / site-packages / jinja2 / environment.py View on Github external
.. versionchanged:: 2.4
           If `names` contains a :class:`Template` object it is returned
           from the function unchanged.
        """
        if not names:
            raise TemplatesNotFound(message=u'Tried to select from an empty list '
                                            u'of templates.')
        globals = self.make_globals(globals)
        for name in names:
            if isinstance(name, Template):
                return name
            if parent is not None:
                name = self.join_path(name, parent)
            try:
                return self._load_template(name, globals)
            except TemplateNotFound:
                pass
        raise TemplatesNotFound(names)
github tranquilit / WAPT / lib / site-packages / jinja2 / loaders.py View on Github external
def load(self, environment, name, globals=None):
        for loader in self.loaders:
            try:
                return loader.load(environment, name, globals)
            except TemplateNotFound:
                pass
        raise TemplateNotFound(name)
github ilblackdragon / django-themes / themes / utils.py View on Github external
def _load_template(self, name, globals):
        request = getattr(settings, 'request_handler', None)
        if request:
            for prefix in request.theme.template_dir_list:
                try:
                    return super(CoffinEnvironment, self)._load_template(join(prefix, name), globals)
                except TemplateNotFound:
                    pass
            try:
                return super(CoffinEnvironment, self)._load_template(name, globals)
            except TemplateNotFound:
                raise TemplateNotFound(name)
        else:
            return super(CoffinEnvironment, self)._load_template(name, globals)
github catboost / catboost / contrib / python / Jinja2 / jinja2 / loaders.py View on Github external
def load(self, environment, name, globals=None):
        loader, local_name = self.get_loader(name)
        try:
            return loader.load(environment, local_name, globals)
        except TemplateNotFound:
            # re-raise the exception with the correct filename here.
            # (the one that includes the prefix)
            raise TemplateNotFound(name)
github guildai / guildai / guild / publish.py View on Github external
def _generate_template(state):
    template = state.template
    render_vars = PublishRunVars(state)
    try:
        template.generate(state.run_dest, render_vars)
    except jinja2.TemplateRuntimeError as e:
        raise GenerateError(e, template)
    except jinja2.exceptions.TemplateNotFound as e:
        e.message = "template not found: %s" % e.message
        raise GenerateError(e, template)
github libfirm / libfirm / scripts / jinja2 / loaders.py View on Github external
def get_source(self, environment, template):
        for loader in self.loaders:
            try:
                return loader.get_source(environment, template)
            except TemplateNotFound:
                pass
        raise TemplateNotFound(template)