Вопрос

I want to display images which are stored in database.

If I used this. in view product = Upload_files.objects.get(id=1)

and in form

<img src="/media/{{ form.image }}/" />

then it will show the image of id=1 . But if I want to display all images from database what should I do for that.

I used this in view(not sure it is right)

product = Upload_files.objects.all()

but I don't know what should I write in my form, so that it display all images.

Это было полезно?

Решение

Grab all the products int he view then loop over them in the template.

// View

products = Upload_files.objects.all()

// Template

{% for product in products %}
    <img src="/media/{{ product.image }}/" />
{% endfor %}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top