Troy Davis
Troy Davis

Reputation: 23

Mako template - setting variable

I have a python module builds different charts / graphs using pyplot. The method I'm including in my Mako template returns a string which is the absolute path to the image it produces. I'm trying to include this image in my html site, but keep getting a syntax error with Mako. Here is how everything looks:

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>

I can call plotter.build_graph() without a problem, but as soon as I assign a variable from its returned value I get a syntax error.

Upvotes: 0

Views: 1164

Answers (1)

S.C.A
S.C.A

Reputation: 85

In the tag <% %> you put only python code, you can save your image using

savefig('image.png')

and then in the html access to it with the img tag

Upvotes: 1

Related Questions