[Fixed]-Python/Django – Get value of a ManyToManyField in a for tag

1👍

You have to use 2 forloop for displaying images in manytomany table.

{% for i in slider %}
<li>
    {% for im in i.image.all %}
    <img src="{{im.image.url}}" alt="{{im.name}}"/>
    {% endfor %}
    <h2>{{i.title}}</h2>
    <p>{{i.text}}, {{i.image_url}}</p>
</li>
{% endfor %}

0👍

Article.image is a ManyToMany field. Which image You want to display? First?

<img src="{{i.image.all.0.image.url}}" alt="{{i.title}}"/>

All?

{% for im in i.image.all %}
<img src="{{im.image.url}}" alt="{{im.name}}"/>
{% endfor %}

Leave a comment