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 }}
Answers:
Try
<pre>{{ vroute.comments }}</pre>
HTML collapses whitespace unless you indicate otherwise.
please add:
style="white-space: pre-line"
to your html tag, for example
<span style="white-space: pre-line"> {{ vroute.commnets}}</span>
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 }}
Try
<pre>{{ vroute.comments }}</pre>
HTML collapses whitespace unless you indicate otherwise.
please add:
style="white-space: pre-line"
to your html tag, for example
<span style="white-space: pre-line"> {{ vroute.commnets}}</span>