Hello ! I hope you are well...
I am working on project of registration in a school where I must recover, 
put the information entered by the user in a template and be able to 
translate this template into pdf in the end send the generated PDF file as 
an attachment of a mail that I send back to the user. Until then the other 
processes work, but after sending the email when I consult my mailbox on my 
phone I find the mail sent with the attachment on the other hand when I 
consult my mailbox on my PC or even with a browser (even on) I can not find 
the attachment. I have never encountered this kind of hard-to-understand 
error. Help me please.

def pdf_genarete(request):

form = MyModelForm(request.POST or None)

if form.is_valid():

nom = form.cleaned_data.get("nom")
email = form.cleaned_data.get("email")
obj = MyModel.objects.create(nom=nom, email=email)
print(obj.nom)
print(obj.email)

context = {"models_instance": obj}

pdf = render_to_pdf("pdfapp/template_pdf.html", context)
filename = "mypdf_{}.pdf".format(obj.order_id)
obj.pdf.save(filename, BytesIO(pdf.content))
# print(obj.pdf.name, obj.pdf.size)

subject = "Thank you"
from_email = settings.EMAIL_HOST_USER
to_email = [obj.email]
body = "Votre inscription"

email_pdf = EmailMultiAlternatives(

subject = subject,
body =body,
from_email = from_email,
to=to_email, 
)

instance_attach = obj.pdf.read()
# print(instance.pdf.name, instance.pdf.size)
email_pdf.attach_alternative(instance_attach, "application/pdf")
# import pdb;pdb.set_trace()

email_pdf.send()

return redirect(reverse("home"))

return render(request, "pdfapp/formulaire.html", {"form": form})

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b48bb711-2e89-4cd0-8440-ee7812830b1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to