In Django, I have an HTML template where I would like to insert values for some javascript variable.
<html>
var jsvar= {{ Python_Django_String_VAR}}
</html>
In Django View:
return render(request, pageurl, context)
In Django, I have an HTML template where I would like to insert values for some javascript variable.
<html>
var jsvar= {{ Python_Django_String_VAR}}
</html>
In Django View:
return render(request, pageurl, context)
This questions was duplicate another title. For beginner of Django, I put the answer to be useful :
The {{variable}} is substituted directly into the HTML. Do a view source; it isn't a "variable" or anything like it. It's just rendered text.
Having said that, you can put this kind of substitution into your JavaScript.
<script type="text/javascript">
var a = "{{someDjangoVariable}}";
</script>
This gives you "dynamic" javascript.