Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.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
Python 动态模板中的SendGrid动态颜色_Python_Dynamic_Sendgrid - Fatal编程技术网

Python 动态模板中的SendGrid动态颜色

Python 动态模板中的SendGrid动态颜色,python,dynamic,sendgrid,Python,Dynamic,Sendgrid,是否可以使用SendGrid的动态模板指定文本的颜色 例如: 我正在通过SendGrid Python API传递一个动态变量 如果变量为负整数,则将颜色设为红色 如果变量为正整数,则将颜色设为绿色 动态模板Python文档: 导入json 从sendgrid导入SendGridApicClient 从sendgrid.helpers.mail导入邮件 信息=邮件( from_email='from_email@example.com', 到to@example.com', html_co

是否可以使用SendGrid的动态模板指定文本的颜色

例如: 我正在通过SendGrid Python API传递一个动态变量

  • 如果变量为负整数,则将颜色设为红色
  • 如果变量为正整数,则将颜色设为绿色
动态模板Python文档:

导入json
从sendgrid导入SendGridApicClient
从sendgrid.helpers.mail导入邮件
信息=邮件(
from_email='from_email@example.com',
到to@example.com',
html_content='并且在任何地方都可以轻松完成,即使使用Python也可以。)
message.dynamic_模板_数据={
“主题”:“测试模板”,
'姓名':'某个人',
“城市”:“丹佛”
}
message.template_id='d-F43DAEEEF504760851F727007E0B5D0'
尝试:
sendgrid\u client=SendGridAPIClient(os.environ.get('sendgrid\u API\u KEY'))
response=sendgrid\u client.send(消息)
打印(响应状态\ U代码)
打印(响应.正文)
打印(响应.标题)
例外情况除外,如e:
打印(电子邮件)```
import json
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail

message = Mail(
    from_email='from_email@example.com',
    to_emails='to@example.com',
    html_content='<strong>and easy to do anywhere, even with Python</strong>')
message.dynamic_template_data = {
    'subject': 'Testing Templates',
    'name': 'Some One',
    'city': 'Denver'
}
message.template_id = 'd-f43daeeaef504760851f727007e0b5d0'
try:
    sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
    response = sendgrid_client.send(message)
    print(response.status_code)
    print(response.body)
    print(response.headers)
except Exception as e:
    print(e.message)```