[Answered ]-How can I get an image URL from an image field in an InlineFormset?

1👍

Using the code provided by Alex, and this StackOverflow question, I solved it like this:

{% for picture_field in picture_formset %}
    {% if picture_field.instance.image %}
        <img width="25%" src="{{ picture_field.instance.image.url }}" />
    {% endif %}
{% endfor %}

1👍

Looks like you’re looking for the instance attribute, which is attached to each form in a formset:

{% for picture_form in picture_formset %}
    {% if picture_form.instance %}
        <img src="{{ picture_form.instance.image.url }}" />
    {% endif %}
    {{ picture_form.image }}
{% endfor %}

Leave a comment