用innerHTML插入python字符串,并展示到网页上
<script type="text/javascript">
window.onload=function (){
document.getElementById("job_id").innerHTML={{ data['job_pie'] }}
}
</script>
<div id="e98e1476411e4a41aca9c2e25a4ceea1" style="width:300px; height:300px;"></div>
<script>
var chart_e98e1476411e4a41aca9c2e25a4ceea1 = echarts.init(
document.getElementById('e98e1476411e4a41aca9c2e25a4ceea1'), 'white', {renderer: 'canvas'});
var option_e98e1476411e4a41aca9c2e25a4ceea1 = {
"backgroundColor": "#2c343c",
"color": [
"#c23531",
"#2f4554",
<div id="b05f478aec7844f79c804f40c306bd0c" style="width:300px; height:300px;"></div>
<script>
var chart_b05f478aec7844f79c804f40c306bd0c = echarts.init(
document.getElementById('b05f478aec7844f79c804f40c306bd0c'), 'white', {renderer: 'canvas'});
var option_b05f478aec7844f79c804f40c306bd0c = {
"backgroundColor": "#2c343c",
"color": [
"#c23531",
"#2f4554",
使用了改编码,替换
pie_job = pie.render_embed().encode('ascii').decode("unicode_escape")
# print(pie_job)
pie_job = re.findall(r"(?i)(?<=<body>)[\s|\S]*?(?=</body>)",pie_job)[0]
tihuan_list = [r"<",r">",r""",r"'"]
new_tihuan_list = [r"<",r">",r"'",r'"']
for i in range(len(tihuan_list)):
pie_job = pie_job.replace(tihuan_list[i],new_tihuan_list[i])
能够用innerHTML将字符串插入指定位置,并且能够在网页上显示