My solution is to include
another page with {% load static %}
and script with static reference. {% block xxx %}
expects the first {% yyy %}
not to be other than {% include %}
and {% endblock %}
(the only cases I have observed); so when we use "{% static 'xxx.js' %}"
it breaks and complains. But including another page will put Django in calm.
For example, I have a page homepage
which extends base.html
and has some static js files which are not included in base.html
.
base.html
{% block page %}
{% endblock %}
{% block script %}
{% endblock %}
homepage.html
:
{% extends 'base.html' %}
{% block page %}
...
{% endblock %}
{% block script %}
{% include 'home_js.html'%} <!-- don't use static links here because Django does not like it. -->
{% endblock %}
home_js.html
:
{% load static %}
<script src="{% static 'scripts/jquery.js' %}" ></script>
<script>
function ...
</script>
Now the scripts loads.
So, in a block we cannot use {% %}
tags other than {% block xxx %}
and {% endblock %}
.
I am using Django 5.1.
EDIT:
I found {% verbatim %}
tag to be our savior under such situation.
{% load staticfiles %}
? – Nutter