我目前正在将交换服务器电子邮件集成到我的应用程序中。我可以使用 exchangelib 从我的电子邮件中检索附件。我正在尝试将附件保存到我的 Django 模型文件字段中。但是,它不适用于基于我尝试的不同解决方案的不同错误。任何帮助表示赞赏。谢谢你。以下是我的一些代码:
模型.py
class Attachments(models.Model):
name = models.CharField(max_length=255)
attachment = models.FileField(upload_to="attachments/")
视图.py
for attachment in item.attachments:
if isinstance(attachment, FileAttachment):
attachmentlist.append(attachment.name)
saveattachments = Attachments(
name=attachment.name,
attachment=(attachment.content)
)
saveattachments.save()