【发布时间】:2020-12-12 13:28:06
【问题描述】:
美好的一天,我正在尝试在 django 电子邮件中发送一个 html,请问我还能在代码中添加什么。 电子邮件发送运行良好,但仍显示 html 标签。
from celery import task
from django.template.loader import render_to_string, get_template
from django.core.mail import EmailMessage
from orders.models import Order
@task
def payment_completed(order_id):
order = Order.objects.get(id=order_id)
subject = f'Testing html sending'
message = render_to_string('orders/order/pdf.html', {'order':order})
email = EmailMessage(
subject,
message,
'youremai@gmail.com',
[order.email, 'youremai@gmail.com']
)
email.content_subtype = 'html'
email.send()
我试过render_to_string 和get_template
结果一样
【问题讨论】:
-
能否展示您在电子邮件中看到的内容?因为看起来您的发送电子邮件功能看起来不错。
-
好的,我要把它添加到帖子中
-
能否也显示您尝试过的 get_template 代码?
-
还是一样
标签: python django django-templates django-email