I’ve got a javascript widget written for my Django project, which is included at the top of my templates.
<script src="{{ STATIC_URL }}/js/widget.js"></script>
The widget needs to load its own stylesheet, but since it’s not actually a Django template, it doesn’t know where the static root is. Does it need find its .css relative to itself, or is there a way for Django to tell it about {{ STATIC_URL }}?
You can either do relative URLs in your Javascript, which is probably preferable, or you can define a global variable:
Then, you can use
static_urlanywhere in your JS code.