Django Template Email

[Solved] Django Template Email | Python - Code Explorer | yomemimo.com
Question : HTML template with Django email

Answered by : juan-gt

from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.template import Context
plaintext = get_template('email.txt')
htmly = get_template('email.html')
d = Context({ 'username': username })
subject, from_email, to = 'hello', '[email protected]', '[email protected]'
text_content = plaintext.render(d)
html_content = htmly.render(d)
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()

Source : https://stackoverflow.com/questions/2809547/creating-email-templates-with-django | Last Update : Mon, 25 Apr 22

Answers related to django template email

Code Explorer Popular Question For Python