gpt4 book ai didi

python - Django:将来自管理员的新行存储在数据库中并通过 REST API 返回它们

转载 作者:行者123 更新时间:2023-11-28 16:34:01 24 4
gpt4 key购买 nike

我创建了一个网络应用程序,我正在使用 django 生成的管理来插入一些数据。特别是,我有以下领域:

description = models.TextField(max_length=10000, null=True, blank=True)

在管理员中,它显示为文本区域,我可以在其中插入新的空行。但是当我插入类似的东西时

Some text followed by a new emtpy line.

Some other text.

我在调用 REST API 的 HTML 页面中获得的结果是这样的:

Some text followed by a new emtpy line.   Some other text.

因此,一些空格出现在新行的位置。如果我删除空行并只插入一个换行符,则空格的数量会减少。

访问该字段的 REST API 返回此内容:

Some text followed by a new emtpy line.\r\n\r\nSome other text.

如果描述已正确存储到数据库中,我如何保留空行?

最佳答案

这个问题可以通过为文本容器添加一个css指令来解决:

white-space: pre-line;

关于python - Django:将来自管理员的新行存储在数据库中并通过 REST API 返回它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28917126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com