Home > Enterprise >  IMG tag is not accepting image URL in flask by using
IMG tag is not accepting image URL in flask by using

Time:04-22

code snapshot for my code error which is getting by flask jinja2 while using into html to get images by giving url through jinja2

{% for book in books %}

<div >
  <div >
    <a href="#" ></a>
    <a href="#" ></a>
    <a href="#" ></a>
  </div>
  <div >
    <img src="static/image/{{book['img']}}" alt="{{book['img']}}" />
  </div>
  <div >
    <a href="{{book['url']}}" >Read</a>
  </div>
</div>

{% endfor %}

CodePudding user response:

I think it's to do with how you are accessing your static files, try in the format:

{{ url_for('static', filename='images/image_name.jpg') }}

https://flask.palletsprojects.com/en/1.1.x/tutorial/static/

CodePudding user response:

I see, try:

 <img src="static/image/{{book.img}}" alt="{{book.img}}" />
  • Related