In my web app, the user can make blog posts. When I display the blog post, newlines aren\'t shown because I didn\'t replace the new lines with
tags.
Here's a filter wrote by myself:
import jinja2
@jinja2.evalcontextfilter
def nl2br(eval_ctx, value):
result = jinja2.escape(value).unescape().replace('\n', '
')
if eval_ctx.autoescape:
result = jinja2.Markup(result)
return result
And add the filter to the jinja2.Environment()
by calling:
jinja_env.filters['nl2br'] = nl2br