react + django deploy in heroku and image isn't coming through

Viewed 272

settings.py

STATICFILE_DIRS = [os.path.join(
BASE_DIR, 'build/static')]

STATICFILES_STORGE = 
"whitenoise.storage.CompressedManifestStaticFilesStorage"
 MEDIA_URL = "/media/"

 MEDIA_ROOT = os.path.join(BASE_DIR, "media/images")

 WHITENOISE_ROOT = os.path.join(BASE_DIR, "media")

wsgi.py

import os

from django.core.wsgi import get_wsgi_application
# from whitenoise.django import DjangoWhiteNoise
from whitenoise import WhiteNoise

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dj_gmc.settings')

application = get_wsgi_application()
 # application = DjangoWhiteNoise(application)
 application = WhiteNoise(application, root='build/static')
 application.add_files('build', prefix='more-files/')
 application.add_files('media', prefix='more-files/')

can't find a image source it's work in normal localhost prefect but in deploy all images gone until the frontend image

1 Answers

The problem has been solved after many searches and this solution if someone is interested

settings.py

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

STATICFILES_DIRS = (
  os.path.join(BASE_DIR, 'build/static'),
  os.path.join(BASE_DIR, 'build/media'),
  os.path.join(BASE_DIR, 'media/images')
  )


STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_URL = "/media/"

MEDIA_ROOT = os.path.join(BASE_DIR, "media")

importent urls.py

 from django.views.static import serve

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