jinja2传字符串给javascript

前端之家收集整理的这篇文章主要介绍了jinja2传字符串给javascript前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Jinja renders Python strings without the quotes. The user tries var x = {{ 'value' }} and that renders as var x = value. Whatever value is,it isn’t valid when JavaScript runs it,so the user sees a weird value or gets an error,rather than the string they expected.

Using {{ value|tojson }} produces a JSON string,and since the outer quotes are removed when Jinja renders it,it becomes valid JavaScript with the corect type.

原文链接:https://www.f2er.com/js/414856.html

猜你在找的JavaScript相关文章