I have a large Django project with multiple templates which are merged later on to construct pages dynamically, I am facing a weird issue as follows:
I have a
base.htmlwhich includes all the needed imports, including JS and CSS.I have sub-folders for both CSS/JS in the assets, which are usually imported at the end of
base.html.
Now, as my project got bigger, I decided I'd rather have the scripts imports, e.g:
<script type="text/javascript" src="{% static "js/base.js" %}"></script>
<script type="text/javascript" src="{% static "js/menus/projects.js" %}"></script>
<script type="text/javascript" src="{% static "js/menus/sensors.js" %}"></script>
included in each individual HTML file, instead of all being in the base.html, I expected to have no issues, since as far as I know include statements should also transfer context, for reference sake, those are the include statements of interest:
- in
base.html:
{% include "applications/Devices/deviceDashboard.html" %}
- in
deviceDashboard.html:
{% include "applications/Devices/deviceDashboard/listCard.html" %}
{% include "applications/Devices/deviceDashboard/editCard.html" %}
{% include "applications/Devices/deviceDashboard/graphCard.html" %}
In all of those, if I try to run it as-is I get the following:
TemplateSyntaxError at /
Invalid block tag on line 25: 'static'. Did you forget to register or load this tag?
When I try to use the same script import tags as before, and this issue is gone when I use {% load static %} for each individual page. I have {% load static %} in my base.html, but it only applies in that file, and not to any of the sub-files called through the include function.
Why doesn't the include copy the context here? Or does it not copy "static" by default? I suspect this should be a simple misunderstanding from my part about how include is supposed to work here, but I wasn't able to find anything while searching. Finally, if its how import works, how can I resolve this issue?