0

I want to display an image of an item whose name is saved as 1.jpg where 1 is item id. I am trying to show it using url_for but the image is not showing.

<img class="card-img-top" src="{{url_for('static',filename='img/uploads/item.id.jpg')}}" alt="img">

Is there a way i can dynamically insert item.id value in url_for?

1 Answer 1

1

The below sample should work:

{% for item in items %}
    <img class="card-img-top" src="{{url_for('static',filename='img/uploads/' + item.id + '.jpg')}}" alt="img">
{% endfor %}

[ if id is integer then convert to string like item.id|string ]

Sign up to request clarification or add additional context in comments.

1 Comment

It gives str is undefined. Here jinja2 isnt able to convert the integer to string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.