[Answered ]-Django get uploaded images

1👍

try this

# {{x.display_picture.url}}  <!-- from the media url -->
{% for x in myshoes %}
  <div class="card" style="width: 18rem;">
    <img src="{{x.display_picture.url}}" class="card-img-top" alt="...">
    <div class="card-body">
      <h5 class="card-title">{{x.title}}</h5>
      <p class="card-text">{{x.description}}</p>
      <p class="card-text">{{x.price}}</p>
      {{x.display_picture}}
      <a href="" class="btn btn-primary">Go somewhere</a>
    </div>
  </div>
  {%endfor%}

More about image (media) in django

https://docs.djangoproject.com/en/3.2/topics/files/#using-files-in-models

0👍

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

urlpatterns = [
             path('admin/', admin.site.urls),
          ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

MEDIA_URL and MEDIA_ROOT needed to be added with urlpatterns in project urls.py,
along with MEDIA_URL and MEDIA_ROOT defined in settings.py file

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

Leave a comment