Django 文本字段中的新行
在我的 Django 应用程序中,我有:
models.py
content_don = models.TextField()
我将内容写入该字段,然后使用“提交”保存。问题是,在我的页面上我预览它:
post.html
<p class="article-content mt-3 mb-1"><strong>Description: </strong></p>
<div class="media content-section mt-1 mb-1">
<p class="lead">{{ post.content_don }}</p>
</div>
所有内容都在同一行中。现在,我在表单输入期间写入文本时输入了一些行。这是为什么?
In my Django app I have:
models.py
content_don = models.TextField()
I write content into that field and then save it with 'Submit'. Problem is, on my page I preview it with:
post.html
<p class="article-content mt-3 mb-1"><strong>Description: </strong></p>
<div class="media content-section mt-1 mb-1">
<p class="lead">{{ post.content_don }}</p>
</div>
All content is in the same row. There are now rows which I typed in when I wrote text during form input. Why is that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTML 需要将换行符转换为标记,通常是
。有一个 Django 内置 linebreaks 可以做到这一点。HTML needs the newlines converted into markup, typically
<br>
. There's a Django builtin linebreaks to do this.