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 Answer 1

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

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.