Send query parameters by e-mail Django

0

How can I send parameters of a query to the body of a message, and send it by email.

The e-mail is already sent, but I need to send parameters.

    autorizar=AutorizacionDocumentos.objects.get(id=idDoc.id)



    asunto = 'autorizaciòn'
    mensaje = 'El siguiente mensaje es para notificar...'

    msg = EmailMessage(asunto, mensaje, to=['[email protected]'])

    msg.send()
    
asked by Noel L 04.04.2018 в 21:01
source

1 answer

0

To add information to the email you need to create an HTML template beforehand and link it to the email as follows:

from django.template.loader import render_to_string

asunto = 'autorizaciòn'
html = render_to_string('plantillaEmail.html',{'parametro1':1,'mensaje':'El siguiente mensaje es para notificar...'}
msg = EmailMessage(asunto, html, to=['[email protected]'])
msg.send()

You can treat the template as any other Django template and reference the variables with {{parametro1}} .

    
answered by 05.04.2018 в 08:57