[英]Python Flask & Jinja - Getting text from database
I'm using Python with Flask and Jinja2. 我在Flask和Jinja2中使用Python。 I am getting some text from my database (SQLITE 3) and in the database it is displayed properly with line breaks.
我从数据库(SQLITE 3)中获取了一些文本,并且在数据库中正确显示了换行符。 However when I display this text on the website it all displays on one line.
但是,当我在网站上显示此文本时,它们全部显示在一行上。
It should be displayed like this: 它应显示如下:
Hello How are you?
but it's appearing as: 但它显示为:
Hello How are you?
In python strings, newlines are signified via the \\n
character, in HTML you need <br />
for that. 在python字符串中,换行符通过
\\n
字符表示,在HTML中,您需要<br />
。 So you need to add this to your string: 因此,您需要将其添加到您的字符串中:
my_string = my_string.replace("\n", "<br />)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.