从过去的一周起,我正在尝试使用pygal python库创建一个简单的折线图&使用mandrill api发送结果邮件。
我将渲染结果放在"数字" pygal文档中指定的标记。
我可以发送电子邮件,但它完全是空白的。
以下是我的代码。
line_chart = pygal.Line()
line_chart.title = 'Browser usage evolution (in %)'
line_chart.x_labels = map(str, range(2002, 2013))
line_chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1])
line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])
chart = line_chart.render()
html = """<html>
<head>
<script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
<script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/pygal-tooltips.js"></script>
</head>
<body>
<figure>"""
html += chart
html += "</figure></body></html>"
try:
mandrill_client = mandrill.Mandrill(MANDRILL_API_KEY)
message = {}
message['from_email'] = constants.REPORTS
message['subject'] = 'Sending report of non reporting gps devices.'
for email_id in send_to:
to_dict = {}
to_dict['email'] = str(email_id)
to.append(to_dict)
message['to'] = to
message['preserve_recipients'] = True
message['html'] = str(html)
result = mandrill_client.messages.send(message=message, async=False, ip_pool=constants.MANDRILL_MAIN_POOL, send_at=constants.SEND_AT)
except mandrill.Error, e:
print 'A mandrill error occurred: %s - %s' % (e.__class__, e)
任何人都可以告诉我这里的错误吗?
答案 0 :(得分:0)
电子邮件客户端无法呈现Javascript。您附加的图表需要由pygal.js呈现,由于电子邮件无法呈现Javascript,因此会失败。