问题是我试图使用jinja2和weasyprint在python中创建一个图像变量,然后,我想在我的HTML模板(html_out)中传递该图像变量。
我成功创建了图像变量,它出现在变量浏览器中。但是通过将其包含在字典中将其传递给HTML模板只是麻烦。
#this is my image variable
art_work = Image.open('D:/Course/report-automation/Huaweii.png')
#this is my dictionary
template_vars = {"title": title, "start_date": start_date, "end_date": end_date, "price": price,
"total_Impressions": total_impressions, "art_work": art_work, "total_Clicks": total_clicks,
"cpm":cpm, "percentage_mobile": percentage_mobile}
below is the html template with my variable holder:
<div class="image-wrapper">
{{ art_work }}
</div>
答案 0 :(得分:0)
要显示图像,您应该使用<img>
标签。另外,只需在字典中传递图片的src。
<div class="image-wrapper">
<img src=" {{ art_work }}" />
</div>