I was playing around with flask when I came across an odd problem with the \'\\n\' character. it dosen\'t seem to have an effect in my browser, I tried putting
in the
So it turns out that flask autoescapes html tags. So adding the tag just renders them on screen instead of actually creating line breaks.
There are two workarounds to this:
Break up the text into an array
text = text.split('\n')
And then within the template, use a for loop:
{% for para in text %}
{{para}}
{% endfor %}
Disable the autoescaping
First we replace the \n with using replace:
text = text.replace('\n', '
')
Then we disable the autoescaping by surrounding the block where we require this with
{% autoescape false %}
{{text}}
{% endautoescape %}
However, we are discouraged from doing this:
Whenever you do this, please be very cautious about the variables you are using in this block.
I think the first version avoids the vulnerabilities present in the second version, while still being quite easy to understand.