0

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

l_sender = []
l_sender.append('mario.rossi@test.com')
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='wepredict@cathedral.ai')
        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

Manuel Santi
  • 1,106
  • 17
  • 46
  • You here *call* `emailsend` *before* it is defined, you should make the `emailsend(l_sender)` *after* the `def emailsend(..)` clause. – Willem Van Onsem Dec 16 '18 at 16:40
  • That being said, it might be useful to show (and first inspect yourself) the traceback. Typically this gives already quite relevant details. – Willem Van Onsem Dec 16 '18 at 16:42

1 Answers1

1

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

hda
  • 192
  • 1
  • 4