1

My Django app sends an email as follows:

mail_subject='Hi'
to_email='xyz@gmail.com'
message=render_to_string('app1/xyz.html',{
                    'user':User1,'var1':'BLUE'})
email = EmailMessage(mail_subject, message, to=[to_email])
            email.send();

xyz.html looks like below: I would like for the following string to be bold

<strong>{{var1}}</strong>

but it just shows as <strong>BLUE</strong> in the email. I would like to see BLUE

Aseem
  • 5,848
  • 7
  • 45
  • 69
  • Did you try to make you 'var1="blue"', And then in your template use the '{{var1 | escape}}' – devdob Oct 19 '18 at 11:50
  • 1
    Or look at this this similar question and answers. https://stackoverflow.com/q/2809547/3140312 – devdob Oct 19 '18 at 11:57

1 Answers1

2
from django.core.mail import send_mail
from django.template.loader import render_to_string



msg_html = render_to_string('templates/xyz.html', {'some_params': some_params})

send_mail(
    'email title',
    'Hi',
    'sender@gmail.com',
    ['xyz@gmail.com'],
    html_message=msg_html,
)

We can create any structure (bold/italic) in xyz.html and it will display nicely inside an email.

Aseem
  • 5,848
  • 7
  • 45
  • 69