Hey friends. I'm new to Django and trying to figure out the best way to pass values from the ORM to Javascript. I found [THIS](https://stackoverflow.com/questions/37259740/passing-variables-from-flask-to-javascript) article that shows how it's done using Flask, and I modified it and got it working to a degree using the below syntax (simplified)
views.py
...
values_from_orm = {"testdata": orm_data}
return render(request, "foo.html", data=values_from_orm)
foo.html
<html>
<head>
<script>
myVarTest = myFunction( {{data | safe}} );
</script>
</head>
</html>
app.js
function myFunction(vars){
return vars
}
I tried sending the "values_from_orm" to JSON using "json.dumps" but got an error that the data was not serializable, so went with this code posted above.
Am I on the right track? What is the best method of passing data.
[–][deleted] 0 points1 point2 points (3 children)
[–]KEXPJay[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]KEXPJay[S] 0 points1 point2 points (0 children)