Thanks to @Cagez's answer, I was able to find a reliable (and recommended) solution.
According to a message on the Flask mailing list , a way to do this is to override flask.Flask.select_jinja_autoescape() . The related snippet in this post demonstrating how to override which autoescaped patterns does not quite work, so I came up with the following that does the job:
class JHtmlEscapingFlask(Flask): def select_jinja_autoescape(self, filename): if filename is None: return False if filename.endswith('.jhtml'): return True return Flask.select_jinja_autoescape(self, filename) app = JHtmlEscapingFlask(__name__)
I put this at the top of my main Flask application file, replacing the usual app = Flask(__name__)
source share