你如何在 Django 中应用从数据库中获取的文本样式?

How do you apply the styling of text fetched from the database in Django?

我正在创建博客。在 post 页面中,我正在从数据库中获取文本,但未应用样式。相反,我得到了 "raw" 输出。

我正在使用 {{post.text}} 获取 post 内容,我得到:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eget leo cursus, tempus leo non, sodales sem.</p>

而不是具有 <p> 样式的文本。

我正在使用 django-ckeditor。

我正在回答我自己,以防有人寻找相同的东西。

您只需将 |safe 添加到文本循环。于是就变成了{{post.text|safe}}.