im使用plotly创建图表并返回div。我想输入div到HTML并作为电子邮件发送。
div = plotly.offline.plot(data, include_plotlyjs=False, output_type='div')
这是代码:
mail_msg = f'''
<p style="font-weight:bold;">nt <font="Times New Roman"><font size="2">This Month:</font></p>
<p>{table_predict_html}</p>
<p style="font-weight:bold;">nt <font="Times New Roman"><font size="2">Contrast:</font></p>
<p>{tot_html}</p>
<p style="font-weight:bold;">nt <font="Times New Roman"><font size="2">Revenue:</font></p>
<script src=“https://cdn.plot.ly/plotly-latest.min.js”></script>
<p>{div}</p>
'''
msg.attach(MIMEText(mail_msg, 'html', 'utf-8'))
table_predict_html和tot_html是html中的表。电子邮件中显示的表格,但对于图表来说都是空白的。那么将DIV插入到HTML的正确方法是什么?
谢谢
JavaScript实际上在大多数邮件客户端中都无法正常工作。对于HTML邮件,您最好坚持使用基本的HTML和图像。MailChimp在主题上写得很好:链接
如果它是静态图表,则可以使用它作为图片文件保存 fig.write_image("images/fig1.png")
并将其作为图片发送。
如果是动态图表,我认为如果您这样做可能会更容易
div1 = div
.to_html()
.replace('<table border="1" class="dataframe">','<table class="table table-striped">')
然后将其发送为HTML。