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

时间:2015-11-16 17:22:00

标签: python html django django-forms

我正在尝试修改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>

1 个答案:

答案 0 :(得分:0)

听起来电子邮件是以文本形式发送的。确保您使用的是以html格式发送的任何方法。

如果您使用send_mail中的django.core.mail,那么除了html_message之外,您还需要提供message参数。