I am trying to pass a json from django to a template html file with javascript staticfile.
view.py
import json
def view(request,...)
...
return render(request,'index.htm',"g1":json.dumps({"id":1,"name":2})
index.html
<head>
<script language=javascript" src="/static/myapp/myscript.js"></script>
</head>
<body onload="init();">
<div>I am here</div>
</body>
myscript.js
var json = {{g1}};
function init(){
}
myscript.js is not working. Without {{g1}} statement in .js file, it works. Please help.