-1

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
  • 11,812
  • 5
  • 19
  • 40
Chaban33
  • 1,236
  • 8
  • 34

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
  • 11,812
  • 5
  • 19
  • 40