[Django]-ImageField Django template

12πŸ‘

βœ…

In template, use:

{% for post in posts %}
<h1> {{post.title}} </h1>
<img src="{{ post.img.url }}"> 
{% endfor %}

You have to add {{ post.img.url }}.

Also, make sure that in urls.py, you have:

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

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

It will Work.

πŸ‘€Piyush Maurya

Leave a comment