仅作为记录,大佬请跳过。
用
{% autoescape off %}
{% endautoescape %}
背景
博主想将.html中的右侧用python数组循环表示后,传给html文件(实现html文件的循环)(python如何将多个字典形成字典数组可参考博主文章传送门)
即:
但发现html引入后,无法实现相应功能
解决
查看html网页源代码,发现单引号’被';代替:
因此要解决如何在html中将字符转换成实体
——发现文章django的HTML转义:
——因此加入上述代码:
{% autoescape off %}
overlays:{{c}}
{% endautoescape %}
——实现:
附:
关于将字符转换为实体,还可用python(能转是能转,但不能解决现在这个问题,因为将字符从python引入到html还会默认转成';):
博主是python3.7版本:
from html.parser import HTMLParser
def decodeHtml(input):
h = HTMLParser()
s = h.unescape(input)
return s
print(decodeHtml('[{'id': 'overlays-divsd0', 'px': 0.0, 'py': 1500.915663, 'width': 500.168067, 'height': 500.3052210000001}]'))
展示:
可发现字符实现转换成实体
回顾:
其他参考: