我只是在用已经写好的python应用程序来研究Jinja2。我可能会以错误的方式解决这个问题,但这是我想要做的。Jinja2/Python将图像插入到html中
from jinja2 import Environment, FileSystemLoader
from weasyprint import HTML
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template("really.html")
template_vars = {"title":"TITLE","graph":'total.png'}
html_out = template.render(template_vars)
HTML(string=html_out).write_pdf("report.pdf")
这几乎产生我想要什么,我得到了一个名为report.pdf PDF格式,但附加的文件,而不是,它是total.png的字符串。这是我第一次使用Jinja,所以希望附上这样的图像是可能的。谢谢。
这是模板,没有多少内容,只是试图做这件作品。
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
<h2>Graph Goes Here</h2>
{{ graph }}
</body>
</html>
我们展示模板 – yedpodtrzitko