【发布时间】:2018-08-09 14:53:40
【问题描述】:
我无法在对象属性的 js 脚本中使用 django 的模板过滤器。
这段代码返回一个js SyntaxError:
<script>
{{ obj.geometry.geojson | safe }}
</script>
如果将过滤器应用于对象,则不会引发错误:
<script>
{{ obj | safe }}
</script>
上面GeoJson文件的内容如下图所示:
{ "type": "Polygon", "coordinates": [ [ [ 3, 36 ], ... }
我显然不想将引号字符 (") 转义为 (&quot;),因此我可以稍后通过 JSON.parse() 将其从字符串转换为对象。
【问题讨论】:
标签: javascript json django django-templates django-template-filters