Custom Filter for Jinja Templates

You may have noticed, prior to this, my blog posts have looked like a wall of text.

That’s because Jinja (Templating engine) was stipping newlines.

To resolve this issue, use a custom filter:

def BlogPostFilter(value):
return value.replace(‘\n’,’
\n’)

app.jinja_env.filters[‘BlogPostFilter’] = BlogPostFilter

{{ blogPost.body | BlogPostFilter }}

… I still need to work on whitespace to get my indentatino looking correct, but it’s a step in the right direction!

Leave a Reply

Your email address will not be published. Required fields are marked *