David J.
David J.

Reputation: 1913

static js doesn't load -- Django

As far as I know I've followed all the steps to properly load my static files. I was able to load a jpg in my template following the instructions here:

However, my Javascript files from my static folder are not loading.

Here is my base.html:

<!DOCTYPE html>
{% load staticfiles %} 
<html>
  <head>
    {% block js %}
    <script src="{% static "js/p5" %}"></script>
    {% endblock %}
    <title>Rango</title>
  </head>
  <body>
    {% block content %}
    {% endblock %}
  </body>
</html>

in settings.py I have:

STATIC_DIR = os.path.join(BASE_DIR, 'static')

STATIC_URL = '/static/'

STATICFILES_DIRS = [STATIC_DIR, ] 

I definitely have p5.js located in /static/js/p5.js, and django.contrib.staticfiles is in my installed apps. When I go to any sites inheriting from base.html, firebug shows that no JS files are being loaded. What am I doing wrong?

Upvotes: 1

Views: 4147

Answers (1)

Sayse
Sayse

Reputation: 43300

This is probably related to your last question

That javascript file is only included in the default block. since you're overriding it, it is not included. So move the block scope below the javascripts to include extra js

{% block js %}
<script src="{{ STATIC_URL }}js/jquery.1.12.4.min.js"></script>
<script src="{{ STATIC_URL }}js/p5.js"
{% endblock %}

should be

<script src="{% static 'js/jquery.1.12.4.min.js' %}"></script>
<script src="{% static 'js/p5.js' %}"></script>
{% block js %}{% endblock %}

Upvotes: 2

Related Questions