dl8
dl8

Reputation: 1270

Single Quotes not showing up properly in HighCharts graph

In my Django template I have the following code:

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 %}
    ]
}]

However, when the name has a single quote in it, such as:

The Story Behind 'Toy Story'

On the graph it gets displayed as:

The Story Behind %#39;Toy Story'

Upvotes: 1

Views: 754

Answers (2)

chiliNUT
chiliNUT

Reputation: 19573

See here

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

and it says

By default in Django, every template automatically escapes the output of every variable tag. Specifically, these five characters are escaped:

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

For individual variables

To disable auto-escaping for an individual variable, use the safe filter:

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

Upvotes: 1

Rohan
Rohan

Reputation: 53326

Try with escapejs or escape filter.

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

    },

Upvotes: 2

Related Questions