简体   繁体   中英

Python Flask & Jinja - Getting text from database

I'm using Python with Flask and Jinja2. I am getting some text from my database (SQLITE 3) and in the database it is displayed properly with line breaks. 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. So you need to add this to your string:

my_string = my_string.replace("\n", "<br />)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM