Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jinja2/Python将图像插入html_Python_Jinja2_Weasyprint - Fatal编程技术网

Jinja2/Python将图像插入html

Jinja2/Python将图像插入html,python,jinja2,weasyprint,Python,Jinja2,Weasyprint,我正在研究将Jinja2与我已经编写的python应用程序一起使用。我可能做得不对,但以下是我想做的 from jinja2 import Environment, FileSystemLoader from weasyprint import HTML env = Environment(loader=FileSystemLoader('.')) template = env.get_template("really.html") template_vars = {"title":"TITL

我正在研究将Jinja2与我已经编写的python应用程序一起使用。我可能做得不对,但以下是我想做的

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>

{{title}}
这里是图表
{{图}}

对于我自己的问题,我有一个答案,我可以简单地将图像url添加到模板中,而无需尝试将其作为变量传入

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
<h2>Graph Goes Here</h2>
 <img src="graph.png">
 </body>
 </html>

{{title}}
这里是图表

我想我把事情复杂化了一点…

给我们看看模板嗨,我正试着做和你完全一样的事情。但是我没有得到PDF格式的图像。我也在使用tornado Web服务器。我得到的是表格而不是PDF格式的图像。你能提供一些帮助吗?我唯一的猜测是确保文件名的路径是正确的。