gpt4 book ai didi

python + django+ EmailMultiAlternatives Template'对象没有属性'encode

转载 作者:行者123 更新时间:2023-12-05 08:00:33 31 4
gpt4 key购买 nike

我正在通过以下方法发送电子邮件:

EmailMultiAlternatives() 

当调用send()方法时;我在某个基类中出错。

lib/email/encoders.py
'Template' object has no attribute 'encode'

Exception Location: C:\Python27\lib\email\encoders.py in encode_7or8bit, line 73

Python Executable: C:\Python27\python.exe

错误路径:

>   return msg.send(fail_silently)

C:\Python27\lib\email\mime\text.py in __init__
> self.set_payload(_text, _charset)

C:\Python27\lib\email\message.py in set_payload
> self.set_charset(charset)

C:\Python27\lib\email\message.py in set_charset
> cte(self)

C:\Python27\lib\email\encoders.py in encode_7or8bit
> orig.encode('ascii')

谁能知道这个错误?

更新使用以下代码帮助我解决了我的问题。

fail_silently=True

t = get_template(template_name)
html_part = t.render(context)
msg = EmailMultiAlternatives(subject,
t,
sender,
recipients,
bcc=bcc)
msg.attach_alternative(html_part, "text/html")

return msg.send(fail_silently)

最佳答案

在使用 django.template.loader 中的 get_template 方法时出现以下错误

错误:'Template' 对象的 AttributeError 没有属性 'splitlines'

对我有用的解决方案

从 django.template.loader 导入 render_to_string

关于python + django+ EmailMultiAlternatives Template'对象没有属性'encode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18055029/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com