0

When I try to replace \n with <br/, it doesn't work as well.>As seen in pic, newlines should be not like this. It should be jump to next lineThis is my html code to display post message.

How can I make newlines become normal and display in the right way?

Allen
  • 145
  • 3
  • 10

4 Answers4

2

I think you're needing <br>tag.

From w3schools.com:

The <br> tag inserts a single line break.

eightShirt
  • 1,457
  • 2
  • 15
  • 29
1

\n is a new line used in plain text, <br /> on the other hand is line break used in HTML

James
  • 773
  • 1
  • 6
  • 15
1

In Flask you can create a template filter

eg:

@app.template_filter('nl2br')
def nl2br(s):
    return s.replace("\n", "<br />")

and use

{{rs.post.message|nl2br}}
Atul Mishra
  • 298
  • 2
  • 11
0

The only time that \n will show up as a rendered line break in HTML, is when it is within a (pre-formatted text) element. The difference between \n and <br /> in php

With the above quote being said, I suggest using <br> rather than \n.

Community
  • 1
  • 1
almost a beginner
  • 1,622
  • 2
  • 20
  • 41