[Answer]-Django template substitution in include JS scripts

1👍

You can either do relative URLs in your Javascript, which is probably preferable, or you can define a global variable:

<script>var static_url = '{{ STATIC_URL }}';</script>
<script src="{{ STATIC_URL }}/js/widget.js"></script>

Then, you can use static_url anywhere in your JS code.

0👍

I would create the STATIC_URL variable in your settings.py file, making it accessible on your entire site.

STATIC_URL = 'https://your.js.server'

Leave a comment