3

I sent in the following array of dictionaries through Python to HTML:

[{'color': '#CFCFC4', 'day': 7}, {'color': '#FDFD96', 'day': 8}]

which then gets sent to a Javascript function using the following line:

generateHTML("{{ colors }}");

However, while sending the array to Javascript, the apostrophes within the array are converted to &#39(;) so that it looks like

[{&#39(;)day&#39(;): 7, &#39(;)color&#39(;): &#39(;)#CFCFC4&#39(;)}, {&#39(;)day&#39(;): 8, &#39(;)color&#39(;): &#39(;)#FDFD96&#39(;)}]

with the parentheses removed. How can I keep the original form of the array?

Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112
xilinzhou
  • 33
  • 6
  • I can't reproduce this (my output is just regular apostrophes), but may I suggest trying to use jinja 2.9's `tojson` filter? It might handle this for you, as well as being safer in general. http://jinja.pocoo.org/docs/2.9/templates/#tojson – Oliver Fawcett Sep 15 '17 at 10:49
  • Also, depending on whether you have autoescaping enabled, this might be what is causing your issue - read this: http://jinja.pocoo.org/docs/2.9/templates/#html-escaping – Oliver Fawcett Sep 15 '17 at 11:03

0 Answers0