0
私は神社に問題があるJinja2のYAMLのPythonのハッシュ問題
generate.py:何の問題もなく
from jinja2 import Template
import yaml
import sys
import os.path
#Parse the YAML file and produce a Python dict.
yaml_vars = yaml.load(open('parameters.yaml').read())
#Load the Jinja2 template into a Python data structure.
template = Template(open('skel.j2').read())
#Render the configuration using the Jinja2 render method using yaml_vars as arg.
rendered_config = template.render(yaml_vars)
#Write the rendered configuration to a text file.
with open('config.txt', 'w') as config:
config.write(rendered_config)
parameters.yaml
city : LA
skel.j2
123qwe
skel.j2に問題があります
{{
エラー:
Traceback (most recent call last):
File "generate.py", line 10, in <module>
template = Template(open('skel.j2').read())
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 945, in __new__
return env.from_string(source, template_class=cls)
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 880, in from_string
return cls.from_code(self, self.compile(source), globals, None)
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 591, in compile
self.handle_exception(exc_info, source_hint=source_hint)
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "<unknown>", line 2, in template
jinja2.exceptions.TemplateSyntaxError: unexpected end of template, expected 'end of print statement'.
Q:どのように私は、文字列の処理を無効にすることができますか '{{'?