【问题标题】:Mako template - setting variableMako 模板 - 设置变量
【发布时间】:2018-12-02 10:51:49
【问题描述】:

我有一个 python 模块使用 pyplot 构建不同的图表/图形。我在 Mako 模板中包含的方法返回一个字符串,它是它生成的图像的绝对路径。我正在尝试将此图像包含在我的 html 网站中,但一直收到 Mako 的语法错误。一切都是这样的:

mako_template.html

<!DOCTYPE html>
<%! from my_plotter import MyPlotter>
<html>
.
.
<%
    plotter = MyPlotter()
    image = plotter.build_graph()
    <img src="${image}" height="200" width="100%">
%>
.
.
</html>

我可以毫无问题地调用 plotter.build_graph(),但是一旦我从它的返回值中分配一个变量,我就会得到一个语法错误。

【问题讨论】:

    标签: python html mako


    【解决方案1】:

    在标签 你只放了 python 代码,你可以使用

    保存你的图像
    savefig('image.png')
    

    然后在html中用img标签访问它

    【讨论】:

      猜你喜欢
      • 2013-04-16
      • 2014-06-27
      • 1970-01-01
      • 2023-03-16
      • 2011-05-08
      • 2013-05-16
      • 2011-12-26
      • 2012-05-28
      • 2013-10-18
      相关资源
      最近更新 更多