2👍
A better way to do that in Django is to load static in the beginning
{% load static %}
<!DOCTYPE html>
and use the static template tag to build the URL for the given relative path using the configured STATICFILES_STORAGE
, like
<link href="{% static "css/base.css" %}" rel="stylesheet">
This way if you change the static URL you won’t have to change in multiple places of the template. Read more about it here.
For reference, inside the script tags one can use json_script
. Read more about it here.
0👍
In addition to Goncalos’s answer, unless, something has changed during my few years of being inactive in Javascript, I don’t believe you can load js files with the <link>
tag.
so tags like these (where you are trying to load Javascript files):
<link rel="modulepreload" href="/static/_app/immutable/chunks/singletons-eca981c1.js"/>
need to be changed to:
<script type="text/javascript" src="/static/_app/immutable/chunks/singletons-eca981c1.js"><script/>
I’ve had this same error as well. A few times where I was trying to load javascript in <link>
and a few times where I couldn’t load anything – images, scripts, css, etc.
- [Django]-Mathematical Operations on Django Annotations
- [Django]-Django – url tag not working
- [Django]-Django tutorial : TypeError at /polls/3/vote/ reverse() takes no keyword arguments
- [Django]-Django Rest Serializer: Use nested serializer on GET but not POST
- [Django]-Uploading csv file django using a form