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 file add below code, to import the serve lib

from django.views.static import serve

Add the below codes in file (in 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