1

私の 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'
4

2 に答える 2

1

escapejsまたはescapeフィルターで試してください。

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

    },
于 2013-10-15T04:42:23.350 に答える
1

こちらをご覧ください

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

そしてそれは言います

Django のデフォルトでは、すべてのテンプレートはすべての変数タグの出力を自動的にエスケープします。具体的には、次の 5 文字がエスケープされます。

< 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 }}
于 2013-10-15T04:43:07.850 に答える