4

If I use a single quoted attribute in a django template like this:

<button data-json='{"color":"red"}'>click</button>

it automatically gets replaced with:

<button data-json="{"color":"red"}">click</button>

the enclosing '{}' are transformed into "{}" which makes the attributee unreadable for jQuery. I already tried

{% autoescape off %}

without luck.

EDIT:

As an experiment I tried something completely without quotes (in template.html):

<button data=foo>click</button>

which is transformed into (looking at the source code in browser)

<button data="foo">click</button>

(with quotes).

I know you could rewrite the whole thing as

data-json="{'color':'red'}"

and then do a javascript .replace() to make it valid json - but this seems very ugly to me. How can one stop the magical replacement?

biodiv
  • 607
  • 6
  • 16

0 Answers0