关于Django和highcharts的汉字编码(unicode-utf8)

2024-05-29 00:11:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我们必须在视图.py,数据为:

series_1 = [
{'type': 'column', 'data': [4056], 'name': '二手家具'},
{'type': 'column', 'data': [3016], 'name': '家居百货'},
{'type': 'column', 'data': [3765], 'name': '虚拟物品'},
{'type': 'column', 'data': [4056], 'name': '服饰箱包'},
{'type': 'column', 'data': [3756], 'name': '闲置礼品'},
{'type': 'column', 'data': [4056], 'name': '图书/音乐/运动'},
{'type': 'column', 'data': [3765], 'name': '农用品'},
{'type': 'column', 'data': [4052], 'name': '母婴/儿童用品'},
{'type': 'column', 'data': [4056], 'name': '二手手机'},
{'type': 'column', 'data': [4055], 'name': '美容护肤/化妆品'},
{'type': 'column', 'data': [4055], 'name': '二手笔记本'},
{'type': 'column', 'data': [4055], 'name': '电子数码'},
{'type': 'column', 'data': [3765], 'name': '设备/办公用品'},
{'type': 'column', 'data': [4055], 'name': '台式电脑/网络'},
{'type': 'column', 'data': [4055], 'name': '老年用品'},
{'type': 'column', 'data': [4054], 'name': '家用电器'}]

视图功能是:

^{pr2}$

chart2.html中highcharts的代码是:

<script>
$(function () {
    $('#container').highcharts({
        title: {
            text: 'Tongji',
            x: -20 //center
        },
        yAxis: {
            title: {
                text: 'number'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        series:{{series|safe}}
    });
});
</script>>

当我运行它时,我只能看到这样混乱的代码: enter image description here

如果我使用unicode字符串,如u'二家具',则highcharts也会出现如下错误: enter image description here

我真的不知道怎么处理这个问题,请帮帮我,谢谢!在


Tags: 数据代码textnamepy视图datatitle

热门问题