如何在烧瓶中传递和显示图像列表
How to pass and display list of images in flask
我正在使用 flask 和 ml 进行图书推荐,所以我已将图书的图片 link 收集在一个列表中,但无法弄清楚如何在模板中显示这些图片列表。
这是我将参数传递给模板的代码
@app.route('/search',methods=['GET','POST'])
def search():
choice = request.args.get('search')
# removing all the characters except alphabets and numbers.
# passing the choice to the recommend() function
# passing the choice to the recommend() function
books = recommend(choice)
image=get_image(books)
# if rocommendation is a string and not list then it is else part of the
# recommend() function.
if type(books) == type('string'):
return render_template('read.html', book=books,image=image,s='opps')
else:
return render_template('read.html', book=books,image=image)
但无论如何我都不想在我的主模板中显示这些图像列表。
你能帮我解决一下吗..
提前致谢
使用 jinja for 循环。假设 link 的列表是 images
{% for item in images %}
<li><img src="{{item}}" width="500" height="600"></li>
{% endfor %}
我正在使用 flask 和 ml 进行图书推荐,所以我已将图书的图片 link 收集在一个列表中,但无法弄清楚如何在模板中显示这些图片列表。
这是我将参数传递给模板的代码
@app.route('/search',methods=['GET','POST'])
def search():
choice = request.args.get('search')
# removing all the characters except alphabets and numbers.
# passing the choice to the recommend() function
# passing the choice to the recommend() function
books = recommend(choice)
image=get_image(books)
# if rocommendation is a string and not list then it is else part of the
# recommend() function.
if type(books) == type('string'):
return render_template('read.html', book=books,image=image,s='opps')
else:
return render_template('read.html', book=books,image=image)
但无论如何我都不想在我的主模板中显示这些图像列表。 你能帮我解决一下吗..
提前致谢
使用 jinja for 循环。假设 link 的列表是 images
{% for item in images %}
<li><img src="{{item}}" width="500" height="600"></li>
{% endfor %}