Categories
Django

Django: Upload and Display Images

Go ahead and add the below code to your #setting.py

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

#settings.py

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

Import these packages in root #urls.py

#urls.py

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

Add this line of code to root #urls.py

# urls.py

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

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

#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.

By Tube Mint

I am a YouTuber and I also do niche marketing. In the process of create my niche blog using WordPress, Drupal, and GatsbyJS, I learned a few things like html, css, JS, CMS, MVC frameworks, C++, Python, Ruby, MySQL, Windows and Linux. After some time.. I realized that I can share my knowledge with people on YouTube and through my blog. So, here I am. You can ask me if you have any question about these technologies.
Thanks,
@TubeMint