templates.py 文件源码

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

项目:jenskipper 作者: Stupeflix 项目源码 文件源码
def render(templates_dir, template, context, context_overrides={}):
    '''
    Render a job XML from job definition.

    If *insert_hash* is true, also include a hash of the configuration as text
    in the job description.

    :param templates_dir: location of the jobs templates
    :param template: the path to the job template, relative to *templates_dir*
    :param context: a dict containing the variables passed to the tamplate
    :param context_overrides:
        a mapping that will be deep merged in the final context
    :return:
        a ``(rendered_template, template_files)`` tuple, where
        ``template_files`` is the set of files that were loaded to render the
        template
    '''
    loader = TrackingFileSystemLoader(templates_dir)
    env = jinja2.Environment(loader=loader,
                             autoescape=True,
                             undefined=jinja2.StrictUndefined)
    template = env.get_template(template)
    context = utils.deep_merge(context, context_overrides)
    return template.render(**context), loader.loaded_files
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号