0

I work with blueprint in Flask, and my blueprint is initialized like this:

my_blueprint= Blueprint('my_blueprint', __name__,
    template_folder='templates',
    static_folder='static')

I want to display pictures in my HTML template using <img src="{{ picture.uri }}" alt="..."> where picture.uri is the path to the picture. I built this path using os.path.join('/uploads/', f_name]) where f_name is the filename of the picture.

My directory is built this way:

app
--templates
--static
--uploads
--__init__.py

I don't understand how I can render my picture in the HTML template. What I need to put into the 'src' field of my img tag?

Thanks for your help.

Fred
  • 169
  • 1
  • 3
  • 19

1 Answers1

0

You can load static file using

{{ url_for('static', filename='path/to/file.jpg') }}

Will load file from PROJECT_ROOT/static/path/to/file.jpg

Keep in mind that this is for development use only, you have to resolve assets from webserver on production.

Debendra
  • 1,132
  • 11
  • 22
  • Yes I understand with static folder, but my pictures are under uploads (or assets). How can I pass to the template the correct URL using blueprint? What is the best practice to go on production with Flask and assets using blueprint? Thanks for your help. – Fred Feb 27 '21 at 18:03