0

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)
tensor
  • 3,088
  • 8
  • 37
  • 71
  • Possible duplicate of [Django Template Variables and Javascript](http://stackoverflow.com/questions/298772/django-template-variables-and-javascript) – tensor May 01 '17 at 13:33

1 Answers1

0

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.

tensor
  • 3,088
  • 8
  • 37
  • 71