Forums

media folder not accesible in pythonanywhere

i have this configration in setting.py

  STATIC_URL = '/static/'
  # MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR),'media')
  MEDIA_URL = '/media/'
  CRISPY_TEMPLATE_PACK = 'bootstrap4'
 STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static/")
 ]
 LOCAL_STATIC_CDN_PATH = os.path.join(os.path.dirname(BASE_DIR),"static_cdn")
 STATIC_ROOT = os.path.join(LOCAL_STATIC_CDN_PATH,"static")
 MEDIA_ROOT = os.path.join(LOCAL_STATIC_CDN_PATH,'media')

and in url.py

if settings.DEBUG:
     urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

My static folder is working fine. But when upload media file like image from admin panel. render image to template. It does not show in template.

{% for gallery in totalgalleries %}
<div class="card" style="width: 30rem; height: 23rem; margin: 10px;">
  <img src="{{gallery.image.url}}" class="card-img-top" alt="Gallery" style="width:30rem;height: 20rem;">
  <div class="card-body">
    <p class="card-text" style="color: black;">{{gallery.Title}}</p>
  </div>
</div>
{% endfor %}

If you look at the browser's debug console (in Chrome, that's in the "hamburger" menu, then "More tools", then "Developer tools") do you see any errors? I'm wondering if the URLs for the media files are getting 404 errors, or if they're not being rendered at all.