Flask-Images does not work

≡放荡痞女 提交于 2020-01-17 02:17:29

问题


I'm installed Flask-images for resizing some images. My code are like this:

<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)

There are nothing happens and my Chrome devaloper tools said image's url like this:

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

I know there is another way instead url_for - resized_img_src(). I'm set IMAGES_PATH= os.path.join(APP_ROOT, 'images/'). However this configuration does not work and when I use resized_img_src(), only got broken image icon. I don't have a clue how can fix this.

+Is there any other easy ways to resizing uploaded images?


回答1:


Your template uses showimages whereas your Flask Python code shows showthumnails, I'll assume this is typo and code actually uses same as template.

Are these really the quote characters you are using in your template? You need to use the single and double quotes or escape the inner single ones. Try this instead:

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


来源:https://stackoverflow.com/questions/28259449/flask-images-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!