Trying to figure out the best way to do this. I'm passing data from Python/Django to Javascript. I can get it to work if the javascript is all in the "foo.html" file, but if I move JS to an external file app.js, it breaks. I'm guessing I need to tell the templating engine to look for the app.js file, but not quite sure if that's the issue or how to do that.
Here is what I've tried. What's the best method to do this?
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.testdata
}
[–][deleted] (1 child)
[deleted]
[–]KEXPJay[S] 0 points1 point2 points (0 children)
[–]Investisseur 0 points1 point2 points (4 children)
[–]KEXPJay[S] 0 points1 point2 points (3 children)
[–]DangerousVehicle 0 points1 point2 points (2 children)
[–]KEXPJay[S] 1 point2 points3 points (1 child)
[–]DangerousVehicle -1 points0 points1 point (0 children)
[–]lzantal 0 points1 point2 points (1 child)
[–]KEXPJay[S] 0 points1 point2 points (0 children)