0

I'm trying to pass some variables from my view to my javascript. I cannot seem to find any thing online about converting python lists and dicts to JS.

<script>
    var list = '{{area_dict}}'
    console.log(list)
</script>

the console returned:

{&#39;9&#39;: [[&#39;Walls2&#39;, &#39;20&#39;], [&#39;asd&#39;, &#39;21&#39;]], &#39;22&#39;: [[&#39;BD 1&#39;, &#39;6&#39;]]}

while i just need {'9': [['Walls2', '20'], ['asd', '21']], '22': [['BD 1', '6']]}

It seems to convert my python into HTML; I need it to be the same style as my original python. Are there any django filters for this?

1 Answers1

1

You need to use the safe filter:

<script>
    var list = {{area_dict | safe}}
    console.log(list)
</script>

Or check the other answers for this question

Fcmam5
  • 4,888
  • 1
  • 16
  • 33