Reputation: 77
I have an array of dictionary in python, and I want to pass it to my front end to use.
This is what my pythonArrayObj
looks like:
pythonArrayObj =[{"a":1,"b":2,"c":3}, {"a":4,"b":5,"c":6}, {"a":7,"b":8,"c":9}]
However, the problem is that when I do:
var test = {{ pythonArrayObj }};
It keeps giving an error due to the "
quotation being converted into "
if I try and do json.dumps(pythonArrayObj)
before passing it to my front-end, or '
if I don't.
Does anyone know how I can fix this? I've been stuck on it for the last few days and would really appreciate the help.
Thanks!
Upvotes: 0
Views: 2041
Reputation: 59219
You can use the safe
filter to prevent translation of quote characters:
var test = {{ pythonArrayObj|safe }};
will result in
var test = [{'a': 1, 'c': 3, 'b': 2}, {'a': 4, 'c': 6, 'b': 5}, {'a': 7, 'c': 9, 'b': 8}]
in your HTML source.
Upvotes: 2