Omar Abdelaziz
Omar Abdelaziz

Reputation: 547

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.

Upvotes: 1

Views: 148

Answers (1)

ruffishkimbr
ruffishkimbr

Reputation: 76

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.

Upvotes: 1

Related Questions