0

install whitenoise urls.py setting

urlpatterns += static(settings.STATIC_URL, document_root = STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root = MEDIA_ROOT)
urlpatterns += [re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT, }), ]

also configure static root and static url in settings.py

STATIC_URL = '/static/'
MEDIA_URL = '/images/'

STATIC_ROOT = BASE_DIR / 'staticfiles'
MEDIA_ROOT = BASE_DIR / '/static/images/'
STATICFILES_DIRS = [(os.path.join(BASE_DIR, 'static'))]
shyam rathod
  • 119
  • 6
  • Does this answer your question? [Why does DEBUG=False setting make my django Static Files Access fail?](https://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail) – pigrammer Oct 02 '22 at 14:43

1 Answers1

0

In urls.py file: add this:

from django.views.static import serve

and add those two urlpatterns:

re_path('media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT})
re_path('static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT})
Hashem
  • 595
  • 1
  • 3
  • 8