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, '')
- [Answered ]-How to load Plotly graphs fast in a webpage?
- [Answered ]-Django ignore changed field in formset
- [Answered ]-Mysql is not recognized as a internal or external command
- [Answered ]-IntegrityError at /admin/api/user/6/change/ FOREIGN KEY constraint failed
- [Answered ]-General way of iterating over a dictionary containing multiple mpld3 graph images in Django?
Source:stackexchange.com