0

I have tested my app in development and successfully got it fully functional in development running on my local server. I have now been trying to push it into production and none of the static files are being served. The connection has been successful as the domain shows the app with just plain HTML. However, all static files are returning the same 404 error.

settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))`
STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

404 error image

EDIT: installing whitenoise fixed this!

antv2291
  • 5
  • 1
  • 4

2 Answers2

0

try this :

urls.py

from django.conf.urls.static import static

urlpatterns = [
    ...
    ...

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + \
              static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

settings.py

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

Or just try this command:

python manage.py collectstatic

Ahmed Kolsi
  • 211
  • 2
  • 7
0

try this on top every HTML file if you didn't:

{% load static %}

this is because when you add some static files then you must tell manually the template to load those static file.

for more you can see here