0

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>

n365
  • 1
  • 3
  • You might have a completely different issue. Please post your settings and the whole template. – Selcuk Oct 10 '18 at 06:53
  • What do you mean by "do not seem to load" ? Please inspect the response (status and body) you get for those urls (you can check this in your browser's developers tools or just directly type the url in your browser). – bruno desthuilliers Oct 10 '18 at 06:54
  • Also Include the App directory in your question. – ans2human Oct 10 '18 at 07:01
  • Changed the static URL and now seems to be fine. Don't understand the difference though. Many thanks :) – n365 Oct 10 '18 at 08:04

1 Answers1

0

Seems to work when I change the HTML into: <script type="text/javascript" src="{{STATIC_URL}}/static/app/d3.js"></script>

n365
  • 1
  • 3