I am sending an email using django-post_office, which renders the subject line using django templates:
subject = engine.from_string(self.template.html_content).render(self.context)
Django templates automatically sets autoescape=True for security, which means if you have an HTML character such as Here's an email
it will produce a string with the character escaped: Here's an email
.
How can I disable autoescape when using from_string
and render
in this way to display the email subject appropriately?
An alternative example:
from django.template import engines
template = engines['django'].from_string("My name is {{ my_name }}.")
context = {"my_name": "<FooBar's>"}
print(template.render(context))
Results in:
My name is <FooBar's>.