【问题标题】:How to pass and display list of images in flask如何在烧瓶中传递和显示图像列表
【发布时间】:2021-06-12 16:30:23
【问题描述】:

我正在使用 flask 和 ml 进行图书推荐,因此我已将图书的图片链接收集到一个列表中,但无法弄清楚如何在模板中显示这些图片列表。

这是我将参数传递给模板的代码

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

但无论如何我都不会在我的主模板中显示这些图像列表。 你能帮我解决这个问题吗..

提前致谢

【问题讨论】:

    标签: python flask flask-login


    【解决方案1】:

    使用 jinja for 循环。假设链接列表是图片

    {% for item in images %}
        <li><img src="{{item}}" width="500" height="600"></li>
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 2021-06-28
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多