烧瓶图像不起作用 [英] Flask-Images does not work

查看:149
本文介绍了烧瓶图像不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了Flask-images来调整一些图片的大小。我的代码是这样的:

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

showimages



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

没有任何反应,我的Chrome版本工具说图像的URL是这样的:

 < img src =/ image / user / Untitled-1.png?width = 100放大器;放大器;高度= 100&放大器;放大器;模式=作物> 

我知道还有另外一种方式来代替 url_for - resized_img_src()
我设置了 IMAGES_PATH = os.path.join(APP_ROOT,'images /')
然而,这个配置不起作用,当我使用resized_img_src()时,只有破碎的图像图标。我不知道如何解决这个问题。

+还有其他简单的方法来调整上传图片的大小吗?你的模板使用 showimages ,而你的Flask Python代码显示 showthumnails ,我假设这是错字,代码实际上使用相同的模板。



这些是真正的引号字符正在使用您的模板?您需要使用单引号和双引号,或者转义单引号。试试这个:

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


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?

解决方案

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')}}">

这篇关于烧瓶图像不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆