【问题标题】:How to render file-based template with arguments?如何使用参数渲染基于文件的模板?
【发布时间】:2011-05-22 00:28:28
【问题描述】:
from mako.template import Template

stext = "hi"

mytemplate = Template(filename='./t.txt')
print mytemplate.render()

t.txt:

${hi}  , i am here

【问题讨论】:

  • 相对路径在涉及网络内容时通常是错误的。

标签: python mako


【解决方案1】:

将最后一行替换为:

mytemplate.render(hi = "world")

现在,hi 可以等于您喜欢的任何内容,而不仅仅是"world"

【讨论】:

  • 这是在哪里发生的?在线吗?
  • 我发现它一定是“hi = stext”
  • 我明白了,很抱歉让您感到困惑。这是一些文档:makotemplates.org
猜你喜欢
  • 2017-01-02
  • 2022-11-01
  • 2012-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-13
  • 1970-01-01
  • 2011-11-07
相关资源
最近更新 更多