Search code examples
djangodjango-templatesdjango-media

Django reads images without defining MEDIA_URL


I'm new to Django, I know that to display an image I should define MEDIA_URL in the settings.

But when I tried to remove it and use the {{ img.url }} the images are still readable and the browser can see it and display it. The question is does this mean that the MEDIA_URL does not import in displaying images, and why did we declare it if we can use img.url instead.


Solution

  • No images should not be viewable if you remove

    MEDIA_URL = '/media/'
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
    

    from settings.py

    and

    + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    

    If they are, it is probably just because your browser cached the images.

    Try doing CNTL + SHIFT + DEL while in your browser and clearing the cache. Then reload your django web page.