我正在尝试通过电子邮件发送附件,pdf 但我收到以下错误 'file' object has no attribute '__getitem__'
这是我的代码。
created_pdf = open(filename)
from_email = settings.DEFAULT_EMAIL
email = EmailMessage('KenyaBuzz Tickets for %s'%seat1.movie, "There's a pdf attached with the tickets, please print it and provide it at...", from_email,
[seat1.user.email],
)
email.attach(filename, created_pdf, 'application/pdf')
email.send()
最佳答案
attach
的第二个参数应该是数据,而不是文件对象。
email.attach(filename, created_pdf.read(), 'application/pdf')
但是最好使用attach_file
,它直接接受一个文件名:
email.attach_file(filename)
关于python - 发送附件 'file'时Django 1.5错误对象没有属性 '__getitem__',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31320239/