本文整理汇总了Python中jinja2.DebugUndefined方法的典型用法代码示例。如果您正苦于以下问题:Python jinja2.DebugUndefined方法的具体用法?Python jinja2.DebugUndefined怎么用?Python jinja2.DebugUndefined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2
的用法示例。
在下文中一共展示了jinja2.DebugUndefined方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import DebugUndefined [as 别名]
def __init__(self, params):
params = params.copy()
options = params.pop('OPTIONS').copy()
super().__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)
示例2: __init__
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import DebugUndefined [as 别名]
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)
示例3: __init__
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import DebugUndefined [as 别名]
def __init__(self, root_dir, ops_config):
loader = ChoiceLoader([
FileSystemLoader(root_dir),
FileSystemLoader("/")
])
mode = ops_config.get('jinja2.undefined')
undefined = Undefined
if mode == 'StrictUndefined':
undefined = StrictUndefined
elif mode == 'DebugUndefined':
undefined = DebugUndefined
self.env = Environment(loader=loader, undefined=undefined)
self.filter_plugin_loader = PluginLoader(
'FilterModule',
'ansible.plugins.filter',
ops_config.ansible_filter_plugins.split(':'),
'filter_plugins'
)
for filter in self.filter_plugin_loader.all():
self.env.filters.update(filter.filters())
示例4: load_jinja
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import DebugUndefined [as 别名]
def load_jinja(
path, tests, filters, classes, mode,
trim_blocks, lstrip_blocks, keep_trailing_newline):
from jinja2.defaults import BLOCK_START_STRING, BLOCK_END_STRING, \
VARIABLE_START_STRING, VARIABLE_END_STRING, \
COMMENT_START_STRING, COMMENT_END_STRING, \
LINE_STATEMENT_PREFIX, LINE_COMMENT_PREFIX, \
NEWLINE_SEQUENCE
undefined = {
'pedantic': jinja.StrictUndefined,
'debug': jinja.DebugUndefined,
None: jinja.Undefined,
}
env = jinja.Environment(
block_start_string=BLOCK_START_STRING,
block_end_string=BLOCK_END_STRING,
variable_start_string=VARIABLE_START_STRING,
variable_end_string=VARIABLE_END_STRING,
comment_start_string=COMMENT_START_STRING,
comment_end_string=COMMENT_END_STRING,
line_statement_prefix=LINE_STATEMENT_PREFIX,
line_comment_prefix=LINE_COMMENT_PREFIX,
trim_blocks=trim_blocks,
lstrip_blocks=lstrip_blocks,
newline_sequence=NEWLINE_SEQUENCE,
keep_trailing_newline=keep_trailing_newline,
extensions=classes,
undefined=undefined[mode],
loader=jinja.FileSystemLoader(path)
)
env.tests.update(tests)
env.filters.update(filters)
return env
示例5: __init__
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import DebugUndefined [as 别名]
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)