0

I'm new to Flask, so I trying to display data from my dict in HTML.

next_data = '1111111\n222222'
data = {'next_data': next_data}
return render_template("data.html", data=data)

and this is my HTML page

<div>
  <p>{{data['next_data']}}</p>
</div>
<div>
  <p>{{data['name'}}</p>
</div>

the result I'm getting is a string with whitespace instead of \n but my goal is that it should display '222222' on a new line. Any tips?

Expected output = 111111
                  222222
Ruben Helsloot
  • 12,582
  • 6
  • 26
  • 49
Chaban33
  • 1,362
  • 11
  • 38

1 Answers1

1

As described in this answer, use <br/> instead of \n, because the string is treated as HTML, not as a Python string.

next_data = '1111111\n222222'.replace('\n', '<br/>')
Ruben Helsloot
  • 12,582
  • 6
  • 26
  • 49