1

I have passed a variable(list of dictionary) to template in django. I need that variable in java script. How can I get the variable as list without using json.dumps in django views.

1 Answer 1

1

If you have a dictionary in django say myObj, you may simply put this kind of dynamic javascript substitution to use that in javascript

<script type="text/javascript"> 
   var obj = "{{myObj}}"
</script>

Cheers!

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

2 Comments

But 'obj' is string right? I want it as array variable. Is there any option to convert?
you may later do JSON.parse(obj) to get the object equivalent to python's dictionary

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.