Flask-Images not working

I set Flask images to resize some images. My code is as follows:

<img src = '{{url_for('showimages', filename = market.thumbnail, width=100, height=100, mode='crop')}}'> 

showimages :

 @app.route('/image/user/<filename>') def showthumbnail(filename): return send_from_directory(app.config['UPLOAD_FOLDER'], filename) 

Nothing happens, and my Chrome devaloper tools display the image URL as follows:

 <img src="/image/user/Untitled-1.png?width=100&amp;height=100&amp;mode=crop"> 

I know that there is another way instead of url_for - resized_img_src() . I set IMAGES_PATH= os.path.join(APP_ROOT, 'images/') . However, this configuration does not work, and when I use resized_img_src (), only the icon with the damaged image appears. I do not know how to fix this.

+ Are there any other ways to resize uploaded images?

0
source share
1 answer

Your template uses showimages , while Flask Python code shows showthumnails , I assume this is a typo and the code actually uses the same as the template.

Are these characters the codes you use in your template? You need to use single and double quotes or avoid inner single quotes. Try instead:

 <img src="{{url_for('showimages', filename=market.thumbnail, width=100, height=100, mode='crop')}}"> 
0
source

All Articles