gen_template.py 文件源码

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

项目:powerdns-shell-wrapper 作者: opensource-expert 项目源码 文件源码
def generate(self, zone, json_data=None):
        # compute local script location to find template_dir
        me = os.path.realpath(__file__)
        template_dir = os.path.dirname(me) + '/.'

        self.d['domain'] = zone

        # override with json
        if json_data:
            self.d.update(json.loads(json_data))

        env = Environment(loader=FileSystemLoader(template_dir))
        # add to_json filer in jinja2
        # so json can be dumped with in jinja2: {{ var | to_json }}
        env.filters['to_json'] = json.dumps

        template = env.get_template(self.zonetemplate)
        json_str = template.render(self.d)
        return json_str
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号