Django 生成的电子邮件无法正确呈现

Django generated email doesn't render properly

我正在尝试修改 django-registration 中的密码剩余表单以包含超链接。我对 activation_email.html 使用了完全相同的代码,但它不适用于 password_reset_email.html。生成的电子邮件打印所有 html 标签,如 < p >。我错过了什么?

下面是 password_reset_email.html 的代码:

{% load i18n %}
<!doctype html>
<html lang="en">

{% blocktrans %}Hello,{% endblocktrans %}

{% blocktrans %}
To reset your password, please click the following link:
{% endblocktrans %}
<body>
    <p> 
        <a href="http://{{site.domain}}{% url 'auth_password_reset_confirm' uid token %}">
            Reset password
        </a>
    </p>
</body>
{% blocktrans %}
If you do not wish to reset your password, please ignore this message.
{% endblocktrans %}

{% blocktrans %}Thanks,{% endblocktrans %}
{% blocktrans %}Management Team{% endblocktrans %}


{# This is used by django.contrib.auth #}

这里是activation_email.html的代码进行比较。这会生成正确的结果。

{% load i18n %}
<!doctype html>
<html lang="en">

<head>
    <title>{{ site.name }} {% trans "registration" %}</title>
</head>

<body>
<p>
    {% blocktrans with site_name=site.name %}
    Hello!
</p>

<p>
    We're ready to activate your account. All we need to do is make sure this is your email address.
    {% endblocktrans %}
</p>    

<p> 
    <a href="http://{{site.domain}}{% url 'registration_activate' activation_key %}">
        Confirm email
    </a>
</p>
<p>
    {% blocktrans %}
    If you didn't create a account, please just delete this email.
    {% endblocktrans %}

</p>
</body>

</html>

听起来电子邮件是作为文本发送的。确保使用任何方法发送 html.

如果您使用 django.core.mail 中的 send_mail,那么除了 message.

之外,您还需要提供 html_message 参数