1

My target is to display an image on a website, with Flask.

The image is in :

/static/img/articles

The image name is : "43.jpg"

Hardcoding it is perfectly working :

<img src="{{ url_for('static', filename='img/articles/43.jpg') }}" alt="no picture">

However, i need the path to be dynamic (the image is 43 today, maybe 17 tomrrow and 58 after tomorrow).

I tried everything, for example this :

last_id_jpg = r"img/article/43.jpg"

return render_template("index3.html",
                        last_id_jpg = last_id_jpg
                       )

with :

<img src="{{ url_for('static', filename=last_id_jpg) }}" alt="no picture">

or :

<img src="{{ url_for('static', filename='last_id_jpg') }}" alt="no picture">

But can't find the path to the designed image (the webpage displays "no picture"). I made some researches and everything seems OK

What is wrong in my code ?

davidism
  • 121,510
  • 29
  • 395
  • 339
Alex Dana
  • 1,076
  • 3
  • 14
  • 30

1 Answers1

1

You have a typo on your last_id_jpg. It should be

last_id_jpg = r"img/articles/43.jpg" # article with s

not

last_id_jpg = r"img/article/43.jpg"
bertdida
  • 4,988
  • 2
  • 16
  • 22