簡體   English   中英

如何在 html 中顯示 email 的格式化正文 - Python/Django/PostgreSQL

[英]How to display formatted body of an email in html - Python/Django/PostgreSQL

我從 Outlook 檢索電子郵件並將它們存儲在 PostgreSQL 中。 然后我在帶有 Django 的 a.html 頁面中顯示電子郵件:

{% extends "base.html" %}
{% load static %}
{% block page_content %}

    {% for i in ticket %}
        <p>Requester: {{i.requester}}</p>
        <P>Subject: {{i.title}}</p>
        <p>Description: {{i.description}}</p>
    {% endfor %}
{% endblock %}

email 的主體(i.description)具有 html xmlns 文件的格式,例如:

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head>

<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
    {font-family:"Cambria Math";
    panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0cm;
    margin-bottom:.0001pt;
    font-size:11.0pt;
    font-family:"Calibri",sans-serif;
    mso-fareast-language:EN-US;}
span.EmailStyle17
    {mso-style-type:personal-compose;
    font-family:"Calibri",sans-serif;
    color:windowtext;}
.MsoChpDefault
    {mso-style-type:export-only;
    font-family:"Calibri",sans-serif;
    mso-fareast-language:EN-US;}
@page WordSection1
    {size:612.0pt 792.0pt;
    margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
    {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Testing how body works now<o:p></o:p></p>
...

如何使用此 html xmlns 文本格式顯示 email,使其保持原始格式? 有沒有辦法將該文本牆嵌入到 html 中?

預期的:

預期外觀

目前顯示:

當前顯示

我試過<p><embed type="text/html" src={{i.description}}></p>

{{i.description}}可以是純文本格式,但在頁面上顯示時格式仍然被破壞。

嘗試使用safe過濾器:

{{ i.description|safe }}

在此處閱讀更多信息: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM