jinja_utils.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:fuel-ccp 作者: openstack 项目源码 文件源码
def jinja_render(path, context, functions=(), ignore_undefined=False):
    kwargs = {}
    if ignore_undefined:
        kwargs['undefined'] = SilentUndefined
    else:
        kwargs['undefined'] = jinja2.StrictUndefined

    env = jinja2.Environment(loader=jinja2.FileSystemLoader(
        os.path.dirname(path)), **kwargs)
    env.filters['host'] = get_host
    # FIXME: gethostbyname should be only used during config files render
    env.filters['gethostbyname'] = lambda x: x

    for func in functions:
        env.globals[func.__name__] = func
    env.globals['raise_exception'] = j2raise
    content = env.get_template(os.path.basename(path)).render(context)
    return content
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号