Skip to content
Advertisement

Django doesn’t serve all js files in development

I have two js files in my static folder, main.js and animation.js. When I run py manage.py runserver and go to localhost, I only see main.js. I’ve tried hard refreshing Chrome and Firefox, running collectstatic, and it’s still the same. One time when I first loaded the page I saw both js files, but after clicking around the site, the animation.js file just disappeared. My terminal output shows that both js files were found. I’m confused why only one shows up in the browser. If both were missing that would indicate something wrong in settings, but I don’t know with just one missing. What could be my problem?

Here’s my settings.py:

DEBUG = TRUE
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

I include the js files in my base.html which every page extends:

{% load static %}
<!DOCTYPE html>
<html lang="en">
<body>
    <script src="{% static 'js/main.js' %}"></script>
    <script type="module" src="{% static 'js/animation.js' %}"></script>
 </body>
</html>

Advertisement

Answer

I figured out my issue was an error caused by an import problem in the module script.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement