How To Use a Python Variable in an External Javascript (Django)

One way to use a Python variable in an external Javascript is to declare the JS variable in the HTML template through the context object, then pass this variable to the external script code :

HTML
 
<script type="text/javascript"> 
  js_var_from_dj = "{{ django_var }}";
</script>
<script src="https://dzone.com{% static "js/js_file.js" %}" type="text/javascript"></script>

js_file.js :