How can I make newlines become normal and display in the right way?
Asked
Active
Viewed 2,347 times
4 Answers
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
-
-
1Try autoescape off {% autoescape false %} {{rs.post.message}} {% endautoescape %} – Atul Mishra Oct 28 '16 at 06:03
-
-
Thanks @AtulMishra for solve and Thanks Allen for your question – Shahriar Nasim Nafi Jan 25 '20 at 18:41
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
` elements. – Robby Cornelissen Oct 28 '16 at 03:55