Manuel Santi
Manuel Santi

Reputation: 1132

Python send an email passing variable value to html

In my project i have to send an email and pass a value into html code. I try this:

l_sender = []
l_sender.append('[email protected]')
emailsend(l_sender)

def emailsend(l_sender):
    context = {
        'news': 'We have good news!'
    }


    try:
        send_html_email(l_sender, 'Get started with Aida', 'email.html', context, sender='[email protected]')
        print("Email send")
    except Exception as e:
        print(e)

in email.html i insert {{ context.news }} but nothing appen. How can i pass my news val value in mail.html?

Thanks in advance

Upvotes: 0

Views: 653

Answers (1)

hda
hda

Reputation: 192

Why context.news? You must use {{ news }}. The function you called cannot even see that your variable was named context.

Look at this examples: Creating email templates with Django

Upvotes: 1

Related Questions