Domanda

views.py

def manage_photo(request, obj_id):
    form = MediaFileForm(instance=obj)
    if request.method == "POST":
        # Some actions here
        # ...

    return render(request, 'manage_photo.html', {'form': form,})

I would like to display an image thumbnail next to its form field on the form page. For that purpose I use easy-thubmnails module. I would like to write something like this in template:

<img src="{{ form.image|thumbnail_url:'small' }}">

But I can't, because {{ form.image }} is not a File object, which thumbnail_url filter takes as an argument.

I would appreciate any suggestion.

È stato utile?

Soluzione

Since you initialized the form with an instance, you can access that instance: form.instance.image.

Altri suggerimenti

It takes the form form.field.value

<img src="{{ form.image.value|thumbnail_url:'small' }}">
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top