我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用jinja2.DebugUndefined()。
def __init__(self, filepath, local_variables, global_variables=None): self.config = {} if global_variables: self.config.update(global_variables) new_local_variables = {} env = jinja2.Environment(undefined=jinja2.DebugUndefined) for key, value in local_variables.items(): if six.PY2: value = value.decode('utf8') template = env.from_string(value) new_local_variables[key] = template.render( GLOBALS=global_variables) self.config.update(new_local_variables) self.path = filepath
def __init__(self, params): params = params.copy() options = params.pop('OPTIONS').copy() super(Jinja2, self).__init__(params) self.context_processors = options.pop('context_processors', []) environment = options.pop('environment', 'jinja2.Environment') environment_cls = import_string(environment) if 'loader' not in options: options['loader'] = jinja2.FileSystemLoader(self.template_dirs) options.setdefault('autoescape', True) options.setdefault('auto_reload', settings.DEBUG) options.setdefault('undefined', jinja2.DebugUndefined if settings.DEBUG else jinja2.Undefined) self.env = environment_cls(**options)
def __init__(self, params): params = params.copy() options = params.pop('OPTIONS').copy() super(Jinja2, self).__init__(params) environment = options.pop('environment', 'jinja2.Environment') environment_cls = import_string(environment) options.setdefault('autoescape', True) options.setdefault('loader', jinja2.FileSystemLoader(self.template_dirs)) options.setdefault('auto_reload', settings.DEBUG) options.setdefault('undefined', jinja2.DebugUndefined if settings.DEBUG else jinja2.Undefined) self.env = environment_cls(**options)