Menu Close

How to interpolate Python Django Template Variables and JavaScript?

To interpolate Python Django Template Variables and JavaScript, we can wrap our Django variable in curly braces in our template.

For instance, we write

<script type="text/javascript"> 
  const a = "{{someDjangoVariable}}";
</script>

to interpolate the someDjangoVariable value into the JavaScript code in the template by putting it in curly braces.

Posted in Python, Python Answers