tojson(4)}}; My settings is a dict {'name': 'Russian name Саша', 'id': 12345}. If I render it, i get: let SETTINGS = { "name": "Russian name …

Found

a way

let SETTINGS = {{settings|tojson(4)}};

to supply rest parameters to {'name': 'Russian name Саша', 'id': 12345} filter.

let SETTINGS = {
    "name": "Russian name \u0421\u0430\u0448\u0430",
    "id": 12345
}

Starting with Jinja 2.9

json.dumps(data, encure_ascii=False)

policiestojson() can be configured on the environment which can slightly influence how filters and other template constructs behave. They can be configured with the policies attribute.

All I had to do:

解决方案:

我的模板是用在JS上的我的设置是听写 tojson(). 如果我渲染它,我得到。

我需要获取非escaped的unicode字符。在python中,我可以用同样的方法来获取非拼写的unicode字符。但是 过滤器只接受一个参数(缩进)。

env = jinja2.Environment()
env.policies['json.dumps_kwargs'] = {'ensure_ascii': False, 'sort_keys': True}

我的模板是用于JS的 let SETTINGS = {{settings

本文来自投稿,不代表实战宝典立场,如若转载,请注明出处:https://www.shizhanbaodian.com/baodian/98303.html