首页 > 解决方案 > 序列化文本块 django rest-framework 并使用 react 显示段落

问题描述

我正在创建一个博客并使用 djangorestframework 作为我的后端并为我的前端做出反应。当我序列化我的数据时,我丢失了我的博客条目的格式(以段落形式编写)。有没有办法来解决这个问题。

所以:

博客文章

This is my blog post, and this is my formatting.

My second paragraph.

变成。

[{ 
   "title": "blog post",
   content: "This is my blog post, and this is my formatting My second paragraph."
}
]

当我通过我的反应时它仍然存在

This is my blog post, and this is my formatting My second paragraph.

标签: jsondjangoreactjsdjango-rest-frameworkformat

解决方案


为此,您应该在模型中将竞争字段类型定义为TextField

像这样的东西

content = models.TextField(blank=True, null=True)

希望能帮助到你。


推荐阅读