Django 模板显示原始 HTML 而不是渲染
我正在尝试测试我的 Django 帐户验证电子邮件的电子邮件模板。
但是每次我发送电子邮件而不是看到使用 bootstrap 正确呈现的 html 页面时,电子邮件都会以纯文本形式显示 HTML 代码,我该怎么解决这个问题呢?
acc_verification_email.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="col d-flex justify-content-center w-40 h-100 bg-primary">
<div class="row">
Learning-Electronics
</div>
<div class="row">
<div class="col">
<div class="row">
Obrigado por te registares!
</div>
<div class="row">
Verifica o teu endereço de E-mail
</div>
</div>
</div>
<div class="row">
<p><h2>Olá {% autoescape off %} {{user.first_name}} {% endautoescape %}</h2></p>
<p>Estás quase pronto para começar! Clica no botão abaixo para verificar o teu e-mail e desfrutares da nossa plataforma de aprendizagem</p>
</div>
<div class="row">
{% autoescape off %}
<button type="button" class="btn btn-warning" href="http://{{ domain }}{% url 'account:activate' uidb64=uid token=token %}">VERFICA O EMAIL</button>
{% endautoescape %}
</div>
<div class="row">
<p><h3>Obrigado,</h3></p>
<p><h3>Da Equipa Learning-Electronics</h3></p>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
视图.py
... (some code)
current_site = get_current_site(request)
mail_subject = 'Ativação de conta no Learning-Electronics'
message = render_to_string('acc_active_email.html', {
'user': account,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(account.pk)),
'token': account_activation_token.make_token(account),
})
to_email = account.email
email = EmailMessage(mail_subject, message, to=[to_email])
email.send()
... (some code)
I'm trying to test an email template for my Django Account Verification Email.
But everytime I send the email instead of seeing the html page rendered properly with bootstrap the Email shows the HTML Code in plaintext, what can I do fix this?
acc_verification_email.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="col d-flex justify-content-center w-40 h-100 bg-primary">
<div class="row">
Learning-Electronics
</div>
<div class="row">
<div class="col">
<div class="row">
Obrigado por te registares!
</div>
<div class="row">
Verifica o teu endereço de E-mail
</div>
</div>
</div>
<div class="row">
<p><h2>Olá {% autoescape off %} {{user.first_name}} {% endautoescape %}</h2></p>
<p>Estás quase pronto para começar! Clica no botão abaixo para verificar o teu e-mail e desfrutares da nossa plataforma de aprendizagem</p>
</div>
<div class="row">
{% autoescape off %}
<button type="button" class="btn btn-warning" href="http://{{ domain }}{% url 'account:activate' uidb64=uid token=token %}">VERFICA O EMAIL</button>
{% endautoescape %}
</div>
<div class="row">
<p><h3>Obrigado,</h3></p>
<p><h3>Da Equipa Learning-Electronics</h3></p>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
views.py
... (some code)
current_site = get_current_site(request)
mail_subject = 'Ativação de conta no Learning-Electronics'
message = render_to_string('acc_active_email.html', {
'user': account,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(account.pk)),
'token': account_activation_token.make_token(account),
})
to_email = account.email
email = EmailMessage(mail_subject, message, to=[to_email])
email.send()
... (some code)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)