문제

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.

도움이 되었습니까?

해결책

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

다른 팁

It takes the form form.field.value

<img src="{{ form.image.value|thumbnail_url:'small' }}">
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top