1
xlsxwriter를 사용하여 xlsx 파일을 생성 한 다음 전자 메일의 첨부 파일로 보내려고합니다.Django : 바이트와 유사한 객체를 전자 메일에 첨부하지 못하도록하는 TypeError
def WriteToExcel(project):
output = BytesIO()
workbook = xlsxwriter.Workbook(output)
#putting in data
workbook.close()
xlsx_data = output.getvalue()
# xlsx_data contains the Excel file
return xlsx_data
def project_email (request, project_id):
project = Project.objects.get(id = project_id)
xlsx_data = WriteToExcel(project)
message = EmailMessage("Heading", 'Here is the message.', 'HOST', ['[email protected]'])
message.attach_file(xlsx_data)
message.send()
를 내가 이메일을 보내려고 할 때, 나는 다음과 같은 오류가 있습니다 :
TypeError at /projstatus/1/email
cannot use a string pattern on a bytes-like object
내가 주변에 갈 수있는 방법이 있나요 여기에 내가 지금 가지고있는 무엇인가? xlsx 파일을 비 바이너리로 만들거나 전자 메일에 바이너리 파일을 첨부 할 수있는 함수가 있습니까?