关于#python#的问题:用innerHTML插入python字符串

python字符串

用innerHTML插入python字符串,并展示到网页上

<script type="text/javascript">
    window.onload=function (){
        document.getElementById("job_id").innerHTML={{ data['job_pie'] }}
    }
</script>

问题相关代码 本地python字符串
<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",



运行结果 输出到网页端变成了
&lt;div id=&#34;b05f478aec7844f79c804f40c306bd0c&#34; style=&#34;width:300px; height:300px;&#34;&gt;&lt;/div&gt;
    &lt;script&gt;
        var chart_b05f478aec7844f79c804f40c306bd0c = echarts.init(
            document.getElementById(&#39;b05f478aec7844f79c804f40c306bd0c&#39;), &#39;white&#39;, {renderer: &#39;canvas&#39;});
        var option_b05f478aec7844f79c804f40c306bd0c = {
    &#34;backgroundColor&#34;: &#34;#2c343c&#34;,
    &#34;color&#34;: [
        &#34;#c23531&#34;,
        &#34;#2f4554&#34;,

我的解答思路和尝试过的方法

使用了改编码,替换

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"&lt",r"&gt",r"&#34",r"&#39"]
    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将字符串插入指定位置,并且能够在网页上显示