[Answered ]-Django โ€“ Converting from {{STATIC_URL}} to {% static %}

2๐Ÿ‘

โœ…

Iโ€™m not sure what you are trying to do, but if you want to use {{STATIC_URL}}(or any kind of variable) inside js file, youโ€™ll have to inject it from the the template directly to the html, and only than use it on your script, for instance:

index.html (rendered by django view):

<script>
  var staticUrl = '{{STATIC_URL}}';
</script>
<script src="your-script.js"></script>

In your-script.js:

console.log(staticUrl);
๐Ÿ‘คOr Duan

Leave a comment