Jinja2 escape all HTML but img, b, etc
Jinja2 automatically escapes all HTML tags, but I want to not escape some tags (like img , b , and some others). How can I do it? Alex Morega You can write your own filter. The scrubber library is pretty good at cleaning up HTML. The filter will need to wrap the returned string in jinja2.Markup so the template will not re-escape it. Edit: a code example import jinja2 import scrubber def sanitize_html(text): return jinja2.Markup(scrubber.Scrubber().scrub(text)) jinja_env.filters['sanitize_html'] = sanitize_html Sean Vieira You'll want to parse the input on submission using a white list approach