我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用jinja2.utils.missing()。
def __init__(self, templar, globals, locals=None, *extras): ''' Initializes this object with a valid Templar() object, as well as several dictionaries of variables representing different scopes (in jinja2 terminology). ''' self._templar = templar self._globals = globals self._extras = extras self._locals = dict() if isinstance(locals, dict): for key, val in iteritems(locals): if val is not missing: if key[:2] == 'l_': self._locals[key[2:]] = val elif key not in ('context', 'environment', 'template'): self._locals[key] = val
def get_jinja_locals(real_locals): ctx = real_locals.get('context') if ctx: locals = ctx.get_all() else: locals = {} local_overrides = {} for name, value in iteritems(real_locals): if not name.startswith('l_') or value is missing: continue try: _, depth, name = name.split('_', 2) depth = int(depth) except ValueError: continue cur_depth = local_overrides.get(name, (-1,))[0] if cur_depth < depth: local_overrides[name] = (depth, value) for name, (_, value) in iteritems(local_overrides): if value is missing: locals.pop(name, None) else: locals[name] = value return locals
def __init__(self, templar, globals, locals=None, *extras): ''' Initializes this object with a valid Templar() object, as well as several dictionaries of variables representing different scopes (in jinja2 terminology). ''' self._templar = templar self._globals = globals self._extras = extras self._locals = dict() if isinstance(locals, dict): for key, val in iteritems(locals): if key[:2] == 'l_' and val is not missing: self._locals[key[2:]] = val