2012-12-17 25 views

回答

0

不同的文件有什么问题?

>>> from jinja2 import Template 
>>> template = Template('Hello {{ name }}!') 
>>> for n in ["John", "Doe"]: 
>>>  with open(n + ".txt", "w") as f: 
>>>   print >> f, template.render(name=n) 
+0

Noobness and lack of coffee,that's the problem ... – tutuca

+0

@tutuca我的回答是否帮助你解决问题? :) –

1

也许这会有帮助吗?

import jinja2 

env = jinja2.Environment(loader = jinja2.FileSystemLoader('templates/')) 

def render_template(filename_template, filename_output): 
    nice = env.get_template(filename_template).render() 
    with open(filename_output,'w') as fh: 
    fh.write(nice)