user10786952
user10786952

Reputation:

Python looking for image file using 'url_for'

I am trying to find image file a.jpg from abc folder located /var/www/Project/ABC/static/assets/images/abc

And I am using url_forfunction to reach a.jpg

My b.py file located on /var/www/Project/ABC/ccc/b.py

How do I use url_for fuction here?

I have tried using imageFile = url_for('static', filename='assets/images/abc'+ a.jpg')

But this does not get a.jpg file

Can some one help?

Upvotes: 0

Views: 47

Answers (1)

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38922

It doesn't get a.jpg because it's missing the path separator.

imageFile = url_for('static', filename='assets/images/abc' + 'a.jpg')

The right side of the above statement will evaluate to

imageFile = url_for('static', filename='assets/images/abca.jpg')

Import the path module and use that to join the filename paths.

from os import path

imageFile = url_for('static', filename=path.join('assets', 'images', 'abc', 'a.jpg'))

Upvotes: 1

Related Questions