def generate(self, src): """ render template from path may raise a UndefinedException in case a variable is undefined """ if not os.path.exists(src): return '' try: return self._handle_file(src) except UndefinedError as e: err = 'undefined variable: {}'.format(e.message) raise UndefinedException(err)
def generate_string(self, string): """ render template from string may raise a UndefinedException in case a variable is undefined """ if not string: return '' try: return self.env.from_string(string).render(self.variables) except UndefinedError as e: err = 'undefined variable: {}'.format(e.message) raise UndefinedException(err)