Search code examples
pythonflaskjinja2

Display textfield with line breaks in Flask


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 }}

Solution

  • Try

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

    HTML collapses whitespace unless you indicate otherwise.