Django: Upload and Display Images

Go ahead and add the below code to your

This should work in Django 1.8, 2.2, and 3.01 as well

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

Import these packages in root

from django.conf import settings
from django.conf.urls.static import static

Add this line of code to root


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

Finally, add this line of code to the #list.html


<img src="{{ post.thumbnail.url }}" alt="{{post.title}}" width="50%">

Django – Display Images

Watch me display images in Django

Hope, this is going to work for you. If you still can’t display images in your Django app, simply leave your question below.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.