How can I pass my context variables to a javascript file in Django?

In addition to Andrzej Bobak’s answer, you can also generate a global variable in Javascript from your template. For example, your template might generate code like this:

<script>
   var my_chart = {{ the_chart }};
</script>

Your script could then refer to my_chart.

Leave a Comment