1

My Django project is displaying media in templates if debug == True no problem at all but the problem arises when I set debug to False Django fails to load them if debug == False( There are some solutions out there but I am not able to wrap my head around them as I am new to Django ). Can someone please tell me what is the best and easiest way to solve this issue? Note: I want to host my website on my local wifi (not on pythonanywhere or any other web hosting service) Thanks in advance.

1 Answers1

1

For me below method worked: In urls.py I added this line: from django.views.static import serve add those two urls in urlpatterns:

url(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}), 
url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}), 

and both static and media files were accesible when DEBUG=FALSE. Hope it helps For more info. , Take a look at Why does DEBUG=False setting make my django Static Files Access fail?

Sheraram_Prajapat
  • 589
  • 1
  • 9
  • 27
  • . It worked :-) The media files are being displayed now. I have been searching for a solution and you solved it. Once again thank you :-) – Pinjarla Girish Jul 12 '20 at 13:06