Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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 在django中将csv文件附加到电子邮件_Python_Django - Fatal编程技术网

Python 在django中将csv文件附加到电子邮件

Python 在django中将csv文件附加到电子邮件,python,django,Python,Django,我需要创建一个邮件,应该有一个csv文件作为附件。如何将csv文件附加到django中的邮件?要将文件附加到django发送的电子邮件,您必须创建一个实例,并使用.attach()方法附加该文件 例如,假设您在CSV\u数据中有CSV内容: email = EmailMessage('Subject', 'email body', 'from@mail.com', ['to@mail.com']) email.attach('name.csv', csv_data, 'text/csv') em

我需要创建一个邮件,应该有一个csv文件作为附件。如何将csv文件附加到django中的邮件?

要将文件附加到django发送的电子邮件,您必须创建一个实例,并使用
.attach()
方法附加该文件

例如,假设您在
CSV\u数据中有CSV内容:

email = EmailMessage('Subject', 'email body', 'from@mail.com', ['to@mail.com'])
email.attach('name.csv', csv_data, 'text/csv')
email.send()
或者,如果CSV数据位于文件中,则可以使用:

email.attach_file('/full/path/to/file.csv')
有关发送电子邮件的更多信息,请参阅