I just started playing around with Django and the JavaScript in my static files don't seem to load, while other another resources like logo.png seems to load fine. Am I missing something really basic? Or what I am doing wrong?
My setup
- Using Docker with Python 3.5 with and Django 2.1 as described here
- My static files are in
app\static\app
as described here - I have a JavaScript file (
d3.js
) and an image (logo.png
) in the above directory - In my template I have
<script type="text/javascript" href="{% static 'app/d3.js' %}"></script>
- In settings.py I have
DEBUG = True
(default) - On a Windows environment
Tried solutions
- I can find the files with
python manage.py findstatic app/d3.js
- I tried adding
STATICFILES_DIRS
as suggested here, but that didn't seem to work.
Directory
├───project
│ └───__pycache__
└───app
├───migrations
│ └───__pycache_
├───static
│ └───app
├───templates
│ └───app
└───__pycache__
HTML
{% extends 'app/base.html' %}
{% load static %}
{% block content %}
<div id="graphic"></div>
<script type="text/javascript" href="{% static 'app/d3.js' %}"></script>
<script>
D3 things going on here
</script>
{% endblock %}
Edit: Seems to work when I change the HTML into <script type="text/javascript" src="{{STATIC_URL}}/static/app/d3.js"></script>