我有这段代码:
def send(modeladmin, request, queryset):
emails = []
for email in queryset.get().listing.emails.all():
if email.is_valid():
emails.append(email.email)
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
template_data = {
'body': '<p style="color:red">asdasdas</p>'
}
html_body = render_to_string("template.html", template_data)
from_email = "%s <%s>" % (queryset.get().from_identity.full_name, queryset.get().from_identity.email)
msg = EmailMultiAlternatives(subject=queryset.get().subject, from_email=from_email, to=emails, headers={})
msg.attach_alternative(html_body, "text/html")
msg.send()
现在,我收到了带模板的电子邮件,但是这个“正文”数据被转义了,如何在不逃避的情况下进行渲染?
答案 0 :(得分:1)
您可以使用mark_safe()
from django.utils.safestring import mark_safe