Django static files not loading for one app when DEBUG=False [duplicate]

I'm working on a Django project with multiple apps (Home, student, login, etc.).

When I set DEBUG = False in settings.py, the static files (CSS and JS) from my Home app load fine, but the static files from the student app return 404 errors in the browser console like:

GET /static/student/css/dashboard.css 404 (Not Found)
GET /static/student/js/dashboard.js 404 (Not Found)

However, the static files from the Home app still load correctly.

Here's what I've already done: My student app has this structure:

student/ ├── static/ │ └── student/ │ ├── css/ │ │ └── dashboard.css │ └── js/ │ └── dashboard.js

I'm using {% load static %} in the template and referring like this:

<link rel="stylesheet" href="{% static 'student/css/dashboard.css' %}">
<script src="{% static 'student/js/dashboard.js' %}"></script>

In settings.py

DEBUG = False

ALLOWED_HOSTS = ['127.0.0.1', 'localhost']

STATIC_URL = '/static/'

STATIC_ROOT = BASE_DIR / 'staticfiles'

I ran python manage.py collectstatic, and it successfully copied all static files into the staticfiles/ directory.

I also added this in urls.py:

from django.conf import settings from django.conf.urls.static import static

if not settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

My Question: Why are the static files from the Home app working, but the ones from student are not, even though both use the same structure and settings?

What else should I check to fix this 404 error for static files in the student app when DEBUG=False?

Back to Top