Question

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.

Was it helpful?

Solution

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 %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top