i deployed a webapp in Django on render.com but it is not loading the uploaded images. It will show up when i upload those again. but when i re deploy it wont show up again. this is only for uploaded images.
I guess it knows that there are images but it just wont show up.
i tried a lot from information from the internet and django documentations
urls.py
urlpatterns = [
re_path(r'^static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}),
re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
path('',home_view, name='home'),
path('about_us/', about_view, name='about'),
path('projects/', project_view, name='projects'),
path('project_detail/<str:name>', project_details),
path('gallery/', gallery_view, name='gallery'),
path('services', services_view, name='services'),
path('testimonials/', testimonial_view , name='testimonial'),
path('admin/', admin.site.urls),
]
#urlpatterns += static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)
#urlpatterns += staticfiles_urlpatterns()
settings.py
DEBUG = os.environ.get('D_MODE', 'True').lower() == 'True'
ALLOWED_HOSTS = ['*']
db_url = os.environ.get('DB_URL')
DATABASES = {
'default': dj_database_url.parse(db_url)
}
STATIC_URL = "/static/"
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
if DEBUG:
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
else:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
below is the screenshot of the page when loaded: