JSON is appearing as unicode entities in Jinja2 template

前端 未结 3 1207
傲寒
傲寒 2021-01-04 06:20

I using Jinja2 with webapp2.

Jinja2 encodes all \'context\' data into unicode as their doc says. This is proving problematic when I try to insert a json string into

3条回答
  •  悲&欢浪女
    2021-01-04 07:08

    In Jinja 2.9 I followed @Xion's advice to first convert the iterable elements to string using map('string'). The map filter result I then converted to a list which is finally output as JSON using the tojson built-in filter.

    {{ jsonData|map('string')|list|tojson }} 
    

提交回复
热议问题