Django 2.x email 模板渲染

以前是这样的:


from django.template.loader import get_template
from django.template import Context

htmly = get_template('email/contact.html')
d = Context({'contact': contact, 'attachments': attachments})

html = htmly.render(dt)

如果异常:TypeError: context must be a dict rather than Context. 现在变为:


from django.template.loader import get_template

htmly = get_template('email/contact.html')
d = {'contact': contact, 'attachments': attachments}

html = htmly.render(dt)

render方法传入对象从context变为dict

For example, "name@something.com". If someone replies to you it will be via email.
For example, "http://someaddress.com"