繁体   English   中英

单行情不能正确显示在HighCharts图形中

[英]Single Quotes not showing up properly in HighCharts graph

在我的Django模板中,我有以下代码:

series: [{
    name: 'Ratings',
    data: [
    {% for item in graph_data %}
    {
        name: "{{item}}",
        x: Date.UTC({{item.date.year}},{{item.date.month}},{{item.date.day}}),
        y: {{item.rating}}

    },
    {% endfor %}
    ]
}]

但是,当名称中带有单引号时,例如:

The Story Behind 'Toy Story'

在图上它显示为:

The Story Behind %#39;Toy Story'

尝试使用escapejsescape过滤器。

{% for item in graph_data %}
    {
        name: "{{item|escapejs}}",
        x: Date.UTC({{item.date.year}},{{item.date.month}},{{item.date.day}}),
        y: {{item.rating}}

    },

看这里

https://docs.djangoproject.com/en/1.1/topics/templates/

它说

在Django中,默认情况下,每个模板都会自动转义每个变量标签的输出。 具体来说,这五个字符被转义:

< is converted to &lt;
> is converted to &gt;
' (single quote) is converted to &#39;
" (double quote) is converted to &quot;
& is converted to &amp;

对于单个变量

要禁用单个变量的自动转义,请使用安全过滤器:

This will be escaped: {{ data }}
This will not be escaped: {{ data|safe }}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM