本文整理匯總了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)