python - 我们如何在 jinja2/weasyprint python 中传递图像变量
问题描述
问题是我正在尝试使用 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>
解决方案
要显示图像,您应该使用<img>
标签。另外,只需在字典中传递图像的 src。
<div class="image-wrapper">
<img src=" {{ art_work }}" />
</div>
推荐阅读
- soap - 在 zend soap 服务器 WSDL 中创建自定义标头
- power-automate - 我可以使用 ms flow "peek code"/json 来设置新的流程吗?
- python - 在 LAN 上使用 Python 套接字并与 WAN 隔离
- dart - 决定在运行时构造哪种类型
- node.js - 添加逻辑时没有获取标题 - Angular 7
- r - R:计算列中的元素并在没有循环/重新排列的情况下组合
- node.js - Windows 10 邮件渐变不显示
- javascript - 使用 JS 更改没有 id 或类的内联 CSS
- angular - lib.dom.d.ts 中的 Typescript 3.2 升级和响应正文
- npm - Webpack、Scss - 编译前添加cdn服务器路径