'Python/Django: Email template is not rendered. Shows html tags and doesn't convert entities
I am sending emails using a template, but the template is not being properly rendered. It shows the html tags and doesn't render special chars.
It does render the context, for example if I supply it with a "username":some_name then it will properly display the username when I do {{username}}
my_template.html:
<p>hello ø</p>
In views:
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.template import Context
t = get_template('my_template.html')
msg = EmailMultiAlternatives("hi", t.render(Context({})), from_email, [user.email])
msg.send()
The received email shows up with the p tags displayed. Also, the entity appears exactly as written in the template. I'd be fine just using a .txt file except that I need the special chars to be rendered. If I write them directly in the txt file, I get an error when trying to send it.
I have also tried using django's send_mail(). Also adding an html tag to the template. Same result.
Solution 1:[1]
message.content_subtype = 'html'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | zzroxx98 |
