【问题标题】:html template not rendering correctly for dynamic html content in djangohtml 模板无法正确呈现 django 中的动态 html 内容
【发布时间】:2020-05-01 09:10:48
【问题描述】:

我在 HTML 模板渲染中有一个奇怪的问题,我有模板 index.html,在那个模板中我传递了动态内容,我在这里放置了该代码

<p class="font-secondary paragraph-lg text-dark" style="color: black;">
            {{ portal_contact_home_about|safe }}
        </p>

在portal_contact_home_about这个变量中包含"&lt;p&gt;Lorem ipsum&lt;/p&gt;"这样的数据,所以数据应该像这样渲染

<p class="font-secondary paragraph-lg text-dark" style="color: black;">
                <p>Lorem ipsum</p>
            </p>

但它以错误的方式呈现它

    <p class="font-secondary paragraph-lg text-dark" style="color: black;"></p>
<p>Lorem ipsum</p>

谁能帮我解决这个问题?

【问题讨论】:

    标签: python django python-3.x


    【解决方案1】:

    不要使用两个p标签,而是使用如下

    <div class="font-secondary paragraph-lg text-dark" style="color: black;">
      <p>Lorem ipsum</p>
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      相关资源
      最近更新 更多