我在使用JINJA创建xml文件时遇到问题。我没有用烧瓶。这只是用于创建xml文件。
env = Environment(FileSystemLoader(r'C:\Users\template\templates'))
template = env.get_template('template_fie.xml')
keeping my logic here and writing the values to a dictionary.
tempxmldata=template.render(values=values)
我遇到错误:
template = env.get_template('template_file.xml')
File "C:\ProgramData\Anaconda2\lib\site-packages\jinja2\environment.py", line 830, in get_template
return self._load_template(name, self.make_globals(globals))
File "C:\ProgramData\Anaconda2\lib\site-packages\jinja2\environment.py", line 797, in _load_template
raise TypeError('no loader for this environment specified')
TypeError: no loader for this environment specified
您能告诉我如何使用jinga来生成xml文件吗?
答案 0 :(得分:0)
jinja2.Environment在 init 中有多个选项,而且加载程序不是第一个位置
为了使您的代码正常工作,您只需要将loader设置为Environment的关键字参数,如下所示:
env = Environment(loader=FileSystemLoader(r'C:\Users\template\templates'))