Django media files not Loading when DEBUG = FALSE

Django media files not showing with Debug = False on production. It loads without css & media files like images.

This Code is Checked in Django version 2.1

In the url.py file add below code, to import the serve lib

from django.views.static import serve

Add the below codes in urls.py file (in settings.py containing directory)

if not settings.DEBUG:
    urlpatterns += [
        url(r'^uploads/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
        url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),
    ]

Leave a Comment