This is what I am currently doing to transfer a django template variable to a JS variable:
<input type="hidden" id="django_var" value="{{variable}}" />
...
var unique_var = $('#django_var').val();
Is there a more straightforward way to do this in the template, something that would work outside of forms as well? Thank you.
Update: the js variable will be an external file to the template, and thus won’t be able to directly call the django template vars.
In your HTML template header:
The important thing to note is that you define your JS variables in the head before you include your javascript file.
Then in your javascript you can access $my_var