Bri*_*n D 5 python jinja2 fabric
出于某种原因,Jinja声称它无法找到我在Fabric任务中指定的模板:
httpd_local = "/path/to/dir/conf/" # with httpd.conf located here
httpd_remote = "/etc/httpd/conf/httpd.conf"
with lcd(httpd_local):
upload_template(filename='/path/to/dir/conf/httpd.conf', destination=httpd_remote, context=context[hostname], use_jinja=True)
Run Code Online (Sandbox Code Playgroud)
但每次我跑,我都会
jinja2.exceptions.TemplateNotFound: /path/to/dir/conf/httpd.conf
Run Code Online (Sandbox Code Playgroud)
它肯定住在那里.这是怎么回事?
为了澄清oselivanov的答案,这将是你的正确格式的例子:
httpd_local = "/path/to/dir/conf/" # with httpd.conf located here
httpd_remote = "/etc/httpd/conf/httpd.conf"
with lcd(httpd_local):
upload_template(filename='httpd.conf', destination=httpd_remote, template_dir='/path/to/dir/conf', context=context[hostname], use_jinja=True)
Run Code Online (Sandbox Code Playgroud)
小智 2
来自 upload_template 文档字符串:
\n\n\n\n\n或者,如果
\nuse_jinja设置为 True 并且您有 Jinja2\n 模板库可用,则 Jinja 将用于渲染模板\n。默认情况下,将从调用用户的当前工作目录加载模板,或者从template_dir给定的目录加载模板。
\xd0\xa1onfusing 行为。
\n