Answer the question
In order to leave comments, you need to log in
How to display an image in a django template from a model?
This is a stml document from janga:
catalog.html
{% block catalog %}
{% for a in latest_product %}
<p>{{a.product_name}} - {{a.product_price}} рублей</p>
<img src="{% static '{{a.product_img}}' %}">
class Product(models.Model):
product_name = models.CharField('Название товара', max_length=50)
product_img = models.ImageField('Обложка товара', upload_to='static/imgproduct/')
product_price = models.IntegerField('Цена товара', default=0)
def __str__(self):
return self.product_name
class Meta:
verbose_name = 'Товар'
verbose_name_plural = 'Товары'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question