如何在django和mysql中输出带有换行符的段落? [英] How to output a paragraph with line breaks in django and mysql?

查看:540
本文介绍了如何在django和mysql中输出带有换行符的段落?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将文本保存在这样的列中。

 这是文本

这是一个新的行,空格在
之间。$ / pre

但是当我输出Django模板,它出来像这样

 这是文本这是一个新的行,空格在

我必须在视图或模板中处理这个?我如何以数据库中的方式输出?

解决方案

使用 linebreaks linebreaksbr 过滤器:

  {{text | linebreaks}} 

或使用< pre> ...< / pre> 包围文本。

 < pre> {{text}}< / pre> 


I have text saved in a column that looks like this.

This is the text

This is on a new line with a space in between

But when i output it on the Django template, it comes out like this

This is the text This is on a new line with a space in between

Do I have to process this in the views or the template? How might I output this the way it's saved in the database?

解决方案

Use linebreaks or linebreaksbr filter:

{{ text|linebreaks }}

Or surround the text with <pre>...</pre>.

<pre>{{ text }}</pre>

这篇关于如何在django和mysql中输出带有换行符的段落?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆