4
我的應用程序使用django-wkhtmltopdf生成pdf報告。我希望能夠將pdf附加到電子郵件併發送。附加pdf到django的電子郵件
這裏是我的PDF查看:
class Report(DetailView):
template = 'pdf_reports/report.html'
model = Model
def get(self, request, *args, **kwargs):
self.context['model'] = self.get_object()
response=PDFTemplateResponse(request=request,
template=self.template,
filename ="report.pdf",
context=self.context,
show_content_in_browser=False,
cmd_options={'margin-top': 0,
'margin-left': 0,
'margin-right': 0}
)
return response
這裏是我的電子郵件看法:
def email_view(request, pk):
model = Model.objects.get(pk=pk)
email_to = model.email
send_mail('Subject here', 'Here is the message.', 'from',
[email_to], fail_silently=False)
response = HttpResponse(content_type='text/plain')
return redirect('dashboard')
看到這裏如何將文件附加到電子郵件:http://stackoverflow.com/questions/9541837/attach-a-txt-file -in的Python-的smtplib – Anentropic