How do I escape HTML with Jinja2 so that it can be used as a string in JavaScript (jQuery)?
If I were using Django\'s templating system I could write:
$(
I just researched this problem, my solution is to define a filter:
from flask import Flask, Markup app = Flask(__name__) app.jinja_env.filters['json'] = lambda v: Markup(json.dumps(v))
and in the template:
This has the nice feature that myvar can be anything that can be JSON-serialised