0

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!

2
  • 3
    Render it via a JSON serializer. Commented Mar 2, 2016 at 23:16
  • I believe this answer may give you what you need. enter link description here Commented Mar 2, 2016 at 23:33

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.