0

I'm trying to use jsonpickle to send an Object to front-end in JSON format. Here is the code:

#some code here...
return render(
    request,
    'template.html',
    {   
        'json_values': jsonpickle.encode(values),          
    }
)

But, when I try to echo the string generated in my javascript code I'm getting this result when I call console.log({{json_values}}):

[{'&quotid&quot: 7, &quotnovo_peso&quot: &quot13&quot}, {&quotid&quot: 13, &quotnovo_peso&quot: &quot17&quot}]

See the image below in console: enter image description here

I'm using the last Google Chrome version. Am I doing something wrong?

Thank you

WitnessTruth
  • 539
  • 2
  • 9
  • 27
  • How is `json_values` handled in the template? – Klaus D. Nov 09 '18 at 11:35
  • I'm just calling console.log ( {{ json_values }} ) so I will can handle the values. These values are an ID and a Weight as Number value that will be send to an endpoint via ajax. – WitnessTruth Nov 09 '18 at 11:44
  • 1
    I don't use django, but it looks like you want to turn off auto-escaping html for that part.. https://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape so something like -> `console.log({% autoescape off %}{{json_values}}{% endautoescape %})` – Keith Nov 09 '18 at 11:45
  • It worked! Post as an answer please. – WitnessTruth Nov 09 '18 at 11:51

0 Answers0