Display textfield with line breaks in Flask

Question:

I have a form with textfields in Flask, and users enter texts line by line. When I look at the DB the enties are stored with line breaks but when I display it on my website, in Flask templates, it just joins the sentences and I couldn’t display the text line by line anymore.

To illustrate, user enters text as

1

2

3

However, it looks like in my page as:

1 2 3

This is my code in the template:

{{ vroute.comments }}
Asked By: Bassie

||

Answers:

Try

<pre>{{ vroute.comments }}</pre>

HTML collapses whitespace unless you indicate otherwise.

Answered By: Jasmijn

please add:

style="white-space: pre-line"

to your html tag, for example

<span style="white-space: pre-line"> {{ vroute.commnets}}</span>
Answered By: Vahid Rafael
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.