I would like to use django template for e-mail sending. But I should have two version of e-mails - html and plain text. The first version is generated like below:
template_values = {
'company_id': company.id
}
template_file = os.path.join(os.path.dirname(__file__), 'templates/email.html')
html = template.render(template_file, template_values)
Now I should generate plain text from the same file - templates/email.html
, but it contains html tags (like <div style="font-size:13px; margin: 14px; position:relative">
), which I should remove (links should stay, but should be replaced with plain text, for ex., <a href="http://example.com">Example</a>
should be replaced with something like Example (http://example.com)
).
I've read that I shouldn't use regex for this. What kind of built-in GAE library can help me? Or is there any way to use somehow django's striptags?
Once you get the HTML, you need to do something like:
from django.utils.html import strip_tags
template_values = {
'company_id': company.id
}
template_file = os.path.join(os.path.dirname(__file__), 'templates/email.html')
html = template.render(template_file, template_values)
plain_text = strip_tags(html)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With