Make tojson filter in Jinja2 output Unicode instead of escape sequences

This wasn’t documented anywhere, but kudos to the Jinja2 devs for making this so easy to figure out from the source code.

You need to add a new key to the environment:
env.policies['json.dumps_kwargs'] = {'ensure_ascii': False}

This entry was posted in How to’s and tagged . Bookmark the permalink.

2 Responses to Make tojson filter in Jinja2 output Unicode instead of escape sequences

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *